Skip to content

Commit

Permalink
Some more error-handling cleanup in actix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Jun 22, 2024
1 parent fbe169a commit defcf7c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions examples/actix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn make_error() -> Result<HttpResponse, ExampleAppError> {
/// handlers, and implement the actix ResponseError type.
#[derive(Debug)]
enum ExampleAppError {
ParseInt(std::num::ParseIntError),
// May have other cases, for e.g. a backend not responding.
InternalError,
}
impl actix_web::error::ResponseError for ExampleAppError {
Expand All @@ -96,16 +96,9 @@ impl std::fmt::Display for ExampleAppError {
write!(o, "{:?}", self)
}
}
impl std::error::Error for ExampleAppError {}

impl From<std::num::ParseIntError> for ExampleAppError {
fn from(e: std::num::ParseIntError) -> Self {
ExampleAppError::ParseInt(e)
}
}
impl From<std::io::Error> for ExampleAppError {
fn from(value: std::io::Error) -> Self {
println!("Internal error: {value}");
impl<E: std::error::Error> From<E> for ExampleAppError {
fn from(value: E) -> Self {
tracing::error!("Internal error: {value}");
ExampleAppError::InternalError
}
}
Expand Down

0 comments on commit defcf7c

Please sign in to comment.