Skip to content

Error response refactoring step 2 #1929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove duplicate error "caused by" logging
The `impl<E: AppError> fmt::Display for ChainedError<E>` is sufficient.
  • Loading branch information
jtgeibel committed Dec 5, 2019
commit a5a451e15fe1503d29becf768291fa3a76298f3c
20 changes: 1 addition & 19 deletions src/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ struct Bad {
// AppError trait

pub trait AppError: Send + fmt::Display + fmt::Debug + 'static {
fn cause(&self) -> Option<&(dyn AppError)> {
None
}

/// Generate an HTTP response for the error
///
/// If none is returned, the error will bubble up the middleware stack
Expand Down Expand Up @@ -80,9 +76,6 @@ impl dyn AppError {
}

impl AppError for Box<dyn AppError> {
fn cause(&self) -> Option<&dyn AppError> {
(**self).cause()
}
fn response(&self) -> Option<Response> {
(**self).response()
}
Expand Down Expand Up @@ -148,9 +141,6 @@ impl<T> ChainError<T> for Option<T> {
}

impl<E: AppError> AppError for ChainedError<E> {
fn cause(&self) -> Option<&dyn AppError> {
Some(&*self.cause)
}
fn response(&self) -> Option<Response> {
self.error.response()
}
Expand Down Expand Up @@ -284,15 +274,7 @@ impl Error for AppErrToStdErr {}

impl fmt::Display for AppErrToStdErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)?;

let mut err = &*self.0;
while let Some(cause) = err.cause() {
err = cause;
write!(f, "\nCaused by: {}", err)?;
}

Ok(())
self.0.fmt(f)
}
}

Expand Down