Skip to content

Commit

Permalink
Manually implement fmt::Display and drop dependency on derive_more
Browse files Browse the repository at this point in the history
  • Loading branch information
asmarques committed Sep 7, 2024
1 parent 3695e9b commit 7b42201
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ serde_json = "1.0"
reqwest = { version = "0.12", default-features = false }
chrono = { version = "0.4", features = ["serde"] }
chrono-tz = "0.8"
derive_more = "0.99"

[features]
default = ["reqwest/native-tls"]
Expand Down
19 changes: 12 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
use derive_more::Display;

/// Set of errors which can occur when calling the API.
#[derive(Display, Debug)]
#[derive(Debug)]
pub enum Error {
/// Error establishing a network connection.
#[display(fmt = "connection error: {}", _0)]
ConnectionError(String),
/// HTTP error returned by the API.
#[display(fmt = "server returned HTTP status code {}", _0)]
ServerError(u16),
/// Error parsing the API response.
#[display(fmt = "parsing error: {}", _0)]
ParsingError(String),
/// Error returned by the API.
#[display(fmt = "API error: {}", _0)]
APIError(String),
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ConnectionError(e) => write!(f, "connection error: {}", e),
Error::ServerError(e) => write!(f, "server returned HTTP status code {}", e),
Error::ParsingError(e) => write!(f, "parsing error: {}", e),
Error::APIError(e) => write!(f, "API error: {}", e),
}
}
}

impl std::error::Error for Error {}

impl From<reqwest::Error> for Error {
Expand Down

0 comments on commit 7b42201

Please sign in to comment.