1use crate::SmartString;
2use thiserror::Error;
3
4#[non_exhaustive]
6#[derive(Error, Debug, Clone)]
7pub enum CommonError {
8 #[error("Authentication error: {0}")]
9 Auth(SmartString),
11
12 #[error("Network error: {0}")]
13 Network(SmartString),
15
16 #[error("JSON parsing error: {0}")]
17 Json(SmartString),
19
20 #[error("Invalid parameter: {0}")]
21 InvalidParameter(SmartString),
23
24 #[error("Parsing error: {0}")]
25 Parse(SmartString),
27
28 #[error("Internal error: {0}")]
29 Internal(SmartString),
31
32 #[error("Configuration error: {0}")]
33 Config(SmartString),
35
36 #[error("Websocket error: {0}")]
37 Websocket(SmartString),
39
40 #[error("HTTP error: {0}")]
41 Http(SmartString),
43
44 #[error("API error: {0}")]
45 Api(SmartString),
47}
48
49pub type Result<T> = std::result::Result<T, CommonError>;
51
52impl From<simd_json::Error> for CommonError {
54 fn from(err: simd_json::Error) -> Self {
55 Self::Json(err.to_string().into())
56 }
57}
58
59impl From<reqwest::Error> for CommonError {
60 fn from(err: reqwest::Error) -> Self {
61 Self::Network(err.to_string().into())
62 }
63}
64
65impl From<std::io::Error> for CommonError {
66 fn from(err: std::io::Error) -> Self {
67 Self::Internal(err.to_string().into())
68 }
69}
70
71impl From<url::ParseError> for CommonError {
72 fn from(err: url::ParseError) -> Self {
73 Self::Parse(err.to_string().into())
74 }
75}
76
77impl From<reqwest::header::InvalidHeaderValue> for CommonError {
78 fn from(err: reqwest::header::InvalidHeaderValue) -> Self {
79 Self::Http(err.to_string().into())
80 }
81}
82
83impl From<rust_decimal::Error> for CommonError {
84 fn from(err: rust_decimal::Error) -> Self {
85 Self::Parse(err.to_string().into())
86 }
87}