1#[derive(Debug)]
5pub enum Error {
6 Http(ureq::Error),
8 Json(serde_json::Error),
10 Io(std::io::Error),
12 Provider { status: u16, message: String },
14 Config { field: String },
16 DimensionMismatch { expected: usize, got: usize },
18}
19
20impl std::fmt::Display for Error {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 Self::Http(e) => write!(f, "HTTP error: {e}"),
24 Self::Json(e) => write!(f, "JSON error: {e}"),
25 Self::Io(e) => write!(f, "IO error: {e}"),
26 Self::Provider { status, message } => {
27 write!(f, "provider error ({status}): {message}")
28 }
29 Self::Config { field } => write!(f, "missing config: {field}"),
30 Self::DimensionMismatch { expected, got } => {
31 write!(f, "dimension mismatch: expected {expected}, got {got}")
32 }
33 }
34 }
35}
36
37impl std::error::Error for Error {
38 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39 match self {
40 Self::Http(e) => Some(e),
41 Self::Json(e) => Some(e),
42 Self::Io(e) => Some(e),
43 Self::Provider { .. } | Self::Config { .. } | Self::DimensionMismatch { .. } => None,
44 }
45 }
46}
47
48impl From<ureq::Error> for Error {
49 fn from(e: ureq::Error) -> Self { Self::Http(e) }
50}
51
52impl From<serde_json::Error> for Error {
53 fn from(e: serde_json::Error) -> Self { Self::Json(e) }
54}
55
56impl From<std::io::Error> for Error {
57 fn from(e: std::io::Error) -> Self { Self::Io(e) }
58}