Add axum::Error (#150)

Replace `BoxStdError` and supports downcasting
This commit is contained in:
David Pedersen
2021-08-07 19:56:44 +02:00
committed by GitHub
parent 4792d0c15c
commit 75b5615ccd
12 changed files with 88 additions and 65 deletions
+28
View File
@@ -0,0 +1,28 @@
use std::{error::Error as StdError, fmt};
use tower::BoxError;
/// Errors that can happen when using axum.
#[derive(Debug)]
pub struct Error {
inner: BoxError,
}
impl Error {
pub(crate) fn new(error: impl Into<BoxError>) -> Self {
Self {
inner: error.into(),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&*self.inner)
}
}