use std::fmt;
use std::io;
use crate::api::ApiProblem;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
ApiProblem(ApiProblem),
Call(String),
Base64Decode(base64::DecodeError),
Json(serde_json::Error),
Io(io::Error),
Other(String),
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::ApiProblem(a) => write!(f, "{}", a),
Error::Call(s) => write!(f, "{}", s),
Error::Base64Decode(e) => write!(f, "{}", e),
Error::Json(e) => write!(f, "{}", e),
Error::Io(e) => write!(f, "{}", e),
Error::Other(s) => write!(f, "{}", s),
}
}
}
impl From<ApiProblem> for Error {
fn from(e: ApiProblem) -> Self {
Error::ApiProblem(e)
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Json(e)
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Error::Other(s)
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Error::Other(s.to_string())
}
}