x_http/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    #[error("HTTP request failed: {0}")]
8    Request(#[from] reqwest::Error),
9
10    #[error("Invalid URL: {0}")]
11    InvalidUrl(#[from] url::ParseError),
12
13    #[error("JSON parsing error: {0}")]
14    Json(#[from] serde_json::Error),
15
16    #[error("Assertion failed: {0}")]
17    Assertion(String),
18
19    #[error("Status code {expected} expected, got {actual}")]
20    StatusMismatch { expected: u16, actual: u16 },
21
22    #[error("Header '{key}' expected value '{expected}', got '{actual}'")]
23    HeaderMismatch {
24        key: String,
25        expected: String,
26        actual: String,
27    },
28
29    #[error("Expected JSON response, got content-type: {0}")]
30    NotJson(String),
31
32    #[error("JSON path '{path}' not found")]
33    PathNotFound { path: String },
34
35    #[error("Field '{field}' expected value {expected}, got {actual}")]
36    FieldMismatch {
37        field: String,
38        expected: String,
39        actual: String,
40    },
41
42    #[error("IO error: {0}")]
43    Io(#[from] std::io::Error),
44
45    #[error("Configuration error: {0}")]
46    Config(String),
47
48    #[error("TOML parsing error: {0}")]
49    Toml(#[from] toml::de::Error),
50
51    #[error("Interactive prompt error: {0}")]
52    Interactive(String),
53}
54
55impl From<dialoguer::Error> for Error {
56    fn from(err: dialoguer::Error) -> Self {
57        Error::Interactive(err.to_string())
58    }
59}