Allow returning failure::Error from handlers

This implements From<failure::Error> for Error and ResponseError for failure::Compat<T>.
This commit is contained in:
Christopher Armstrong 2018-02-05 10:11:55 -06:00
parent b6d5516e3a
commit c16062d6bc
1 changed files with 11 additions and 0 deletions

View File

@ -10,6 +10,7 @@ use std::error::Error as StdError;
use cookie; use cookie;
use httparse; use httparse;
use futures::Canceled; use futures::Canceled;
use failure;
use failure::{Fail, Backtrace}; use failure::{Fail, Backtrace};
use http2::Error as Http2Error; use http2::Error as Http2Error;
use http::{header, StatusCode, Error as HttpError}; 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` /// Default error is `InternalServerError`
#[cfg(actix_nightly)] #[cfg(actix_nightly)]
default impl<T: StdError + Sync + Send + 'static> ResponseError for T { default impl<T: StdError + Sync + Send + 'static> ResponseError for T {