mirror of https://github.com/fafhrd91/actix-web
Allow returning failure::Error from handlers
This implements From<failure::Error> for Error and ResponseError for failure::Compat<T>.
This commit is contained in:
parent
b6d5516e3a
commit
c16062d6bc
11
src/error.rs
11
src/error.rs
|
@ -10,6 +10,7 @@ use std::error::Error as StdError;
|
|||
use cookie;
|
||||
use httparse;
|
||||
use futures::Canceled;
|
||||
use failure;
|
||||
use failure::{Fail, Backtrace};
|
||||
use http2::Error as Http2Error;
|
||||
use http::{header, StatusCode, Error as HttpError};
|
||||
|
@ -95,6 +96,16 @@ impl<T: ResponseError> From<T> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> ResponseError for failure::Compat<T>
|
||||
where T: fmt::Display + fmt::Debug + Sync + Send + 'static
|
||||
{ }
|
||||
|
||||
impl From<failure::Error> for Error {
|
||||
fn from(err: failure::Error) -> Error {
|
||||
Error { cause: Box::new(err.compat()), backtrace: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// Default error is `InternalServerError`
|
||||
#[cfg(actix_nightly)]
|
||||
default impl<T: StdError + Sync + Send + 'static> ResponseError for T {
|
||||
|
|
Loading…
Reference in New Issue