1use std::fmt;
3use std::io;
4
5use crate::api::ApiProblem;
6
7pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug)]
12pub enum Error {
13 ApiProblem(ApiProblem),
15 Call(String),
17 Base64Decode(base64::DecodeError),
19 Json(serde_json::Error),
21 Io(io::Error),
23 Other(String),
26}
27impl std::error::Error for Error {}
28
29impl fmt::Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 match self {
32 Error::ApiProblem(a) => write!(f, "{}", a),
33 Error::Call(s) => write!(f, "{}", s),
34 Error::Base64Decode(e) => write!(f, "{}", e),
35 Error::Json(e) => write!(f, "{}", e),
36 Error::Io(e) => write!(f, "{}", e),
37 Error::Other(s) => write!(f, "{}", s),
38 }
39 }
40}
41
42impl From<ApiProblem> for Error {
43 fn from(e: ApiProblem) -> Self {
44 Error::ApiProblem(e)
45 }
46}
47
48impl From<serde_json::Error> for Error {
49 fn from(e: serde_json::Error) -> Self {
50 Error::Json(e)
51 }
52}
53
54impl From<io::Error> for Error {
55 fn from(e: io::Error) -> Self {
56 Error::Io(e)
57 }
58}
59
60impl From<String> for Error {
61 fn from(s: String) -> Self {
62 Error::Other(s)
63 }
64}
65
66impl From<&str> for Error {
67 fn from(s: &str) -> Self {
68 Error::Other(s.to_string())
69 }
70}