1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum OriginError {
6 #[error("HTTP error: {0}")]
8 Http(#[from] reqwest::Error),
9
10 #[error("API error ({status}): {message}")]
12 Api {
13 status: u16,
14 code: Option<String>,
15 message: String,
16 command: Option<String>,
17 },
18
19 #[error("JSON error: {0}")]
21 Json(#[from] serde_json::Error),
22
23 #[error("IO error: {0}")]
25 Io(#[from] std::io::Error),
26
27 #[error("{0}")]
29 Config(String),
30}
31
32impl OriginError {
33 pub fn api(status: u16, message: impl Into<String>) -> Self {
34 Self::Api {
35 status,
36 code: None,
37 message: message.into(),
38 command: None,
39 }
40 }
41
42 pub fn api_full(
43 status: u16,
44 code: Option<String>,
45 message: impl Into<String>,
46 command: Option<String>,
47 ) -> Self {
48 Self::Api {
49 status,
50 code,
51 message: message.into(),
52 command,
53 }
54 }
55
56 pub fn config(message: impl Into<String>) -> Self {
57 Self::Config(message.into())
58 }
59}
60
61pub type Result<T> = std::result::Result<T, OriginError>;