use thiserror::Error;
pub(crate) type Result<T> = std::result::Result<T, ConsulError>;
#[derive(Debug, Error)]
pub enum ConsulError {
#[error("Invalid request: {0}")]
InvalidRequest(#[source] serde_json::Error),
#[error("Request error: {0}")]
RequestError(#[source] http::Error),
#[error("Response error: {0}")]
ResponseError(#[source] hyper_util::client::legacy::Error),
#[error("Invalid response: {0}")]
InvalidResponse(#[source] hyper::Error),
#[error("Response deserialization failed: {0}")]
ResponseDeserializationFailed(#[source] serde_json::Error),
#[error("Response string deserialization failed: {0}")]
ResponseStringDeserializationFailed(#[source] std::str::Utf8Error),
#[error("Unexpected response code: {0}, body: {1:?}")]
UnexpectedResponseCode(hyper::http::StatusCode, Option<String>),
#[error("Lock acquisition failure: {0}")]
LockAcquisitionFailure(u64),
#[error("Invalid UTF8: {0}")]
InvalidUtf8(#[from] std::str::Utf8Error),
#[error("Invalid base64: {0}")]
InvalidBase64(#[from] base64::DecodeError),
#[error("Sync IO error: {0}")]
SyncIoError(#[from] std::io::Error),
#[error("Sync invalid response error: {0}")]
SyncInvalidResponseError(#[from] std::str::ParseBoolError),
#[error("Sync unexpected response code: {0}, body: {1}")]
SyncUnexpectedResponseCode(u16, String),
#[error("Consul request exceeded timeout of {0:?}")]
TimeoutExceeded(std::time::Duration),
#[error(
"Unable to resolve service '{0}' to a concrete list of addresses and ports for its instances via consul."
)]
ServiceInstanceResolutionFailed(String),
#[error("UReq error: {0}")]
UReqError(#[from] ureq::Error),
#[error("Failed to delete the token")]
TokenDeleteFailed,
}