Skip to main content

workflow_http/
error.rs

1use thiserror::Error;
2
3/// Errors produced by the HTTP client operations in this crate.
4#[derive(Error, Debug)]
5pub enum Error {
6    /// A custom, free-form error message, including non-success HTTP responses.
7    #[error("Custom: {0}")]
8    Custom(String),
9
10    /// An error originating from the underlying `reqwest` HTTP client.
11    #[error("Reqwest: {0}")]
12    Reqwest(#[from] reqwest::Error),
13
14    /// An error serializing or deserializing JSON.
15    #[error("JSON: {0}")]
16    Json(#[from] serde_json::Error),
17
18    /// The requested operation is not implemented on this platform.
19    #[error("Not implemented")]
20    NotImplemented,
21}
22
23impl From<String> for Error {
24    fn from(s: String) -> Self {
25        Error::Custom(s)
26    }
27}
28
29impl From<&str> for Error {
30    fn from(s: &str) -> Self {
31        Error::Custom(s.to_string())
32    }
33}
34
35impl Error {
36    /// Creates a [`Error::Custom`] error from any value convertible to a string.
37    pub fn custom<T: ToString>(s: T) -> Self {
38        Error::Custom(s.to_string())
39    }
40}