1use core::fmt;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use thiserror::Error;
5
6pub type Result<T> = core::result::Result<T, Error>;
7
8#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ApiError {
11 pub error: i64,
12 pub message: String,
13 pub links: Vec<Value>,
14}
15
16#[derive(Debug, Error)]
17pub enum Error {
18 #[error("Generic error: {0}")]
19 Generic(String),
20
21 #[error("IO error: {0}")]
22 IO(#[from] std::io::Error),
23
24 #[error("Network error: {0}")]
25 NetworkError(#[from] reqwest::Error),
26
27 #[error("JSON error: {0}")]
28 JsonError(#[from] serde_json::Error),
29
30 #[error("XML error: {0}")]
31 XmlError(#[from] serde_xml_rs::Error),
32
33 #[error("API error: {0}")]
34 ApiError(#[from] ApiError),
35
36 #[error("Unknown error: {0}")]
37 UnknownError(String),
38}
39
40impl fmt::Display for ApiError {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 write!(f, "API Error {}: {}", self.error, self.message)
43 }
44}
45
46impl std::error::Error for ApiError {}