use crate::response::ApiErrorResponse;
use std::fmt;
#[derive(Debug)]
pub enum ClientError {
General(String),
UnexpectedResponseType(String),
ApiError(ApiErrorResponse),
}
impl ClientError {
pub fn to_string(&self) -> String {
match self {
ClientError::General(error) => error.clone(),
ClientError::UnexpectedResponseType(error) => error.clone(),
ClientError::ApiError(error) => error.to_string(),
}
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ClientError::General(error) => write!(f, "{}", error),
ClientError::UnexpectedResponseType(error) => write!(f, "{}", error),
ClientError::ApiError(error) => write!(f, "{}", error.to_string()),
}
}
}
impl From<String> for ClientError {
fn from(err: String) -> ClientError {
ClientError::General(err)
}
}
impl From<serde_json::Error> for ClientError {
fn from(err: serde_json::Error) -> Self {
ClientError::General(err.to_string())
}
}
impl From<serde_urlencoded::ser::Error> for ClientError {
fn from(err: serde_urlencoded::ser::Error) -> Self {
ClientError::General(err.to_string())
}
}
impl From<&str> for ClientError {
fn from(err: &str) -> ClientError {
ClientError::General(String::from(err))
}
}
impl From<reqwest::Error> for ClientError {
fn from(err: reqwest::Error) -> ClientError {
ClientError::General(err.to_string())
}
}