mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-27 17:22:57 +01:00
added default ErrorResponse for std::error::Error
This commit is contained in:
parent
5529ea0428
commit
f33c489154
@ -32,6 +32,9 @@ tls = ["native-tls", "tokio-tls"]
|
||||
# openssl
|
||||
alpn = ["openssl", "openssl/v102", "openssl/v110", "tokio-openssl"]
|
||||
|
||||
# nightly
|
||||
nightly = []
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
failure = "0.1"
|
||||
|
21
src/error.rs
21
src/error.rs
@ -4,12 +4,16 @@ use std::str::Utf8Error;
|
||||
use std::string::FromUtf8Error;
|
||||
use std::io::Error as IoError;
|
||||
|
||||
#[cfg(feature="nightly")]
|
||||
use std::error::Error as StdError;
|
||||
|
||||
use cookie;
|
||||
use httparse;
|
||||
use failure::Fail;
|
||||
use http2::Error as Http2Error;
|
||||
use http::{header, StatusCode, Error as HttpError};
|
||||
use http_range::HttpRangeParseError;
|
||||
use serde_json::error::Error as JsonError;
|
||||
|
||||
// re-exports
|
||||
pub use cookie::{ParseError as CookieParseError};
|
||||
@ -64,18 +68,23 @@ impl From<Error> for HttpResponse {
|
||||
}
|
||||
}
|
||||
|
||||
/// `Error` for any error that implements `ErrorResponse`
|
||||
impl<T: ErrorResponse> From<T> for Error {
|
||||
fn from(err: T) -> Error {
|
||||
Error { cause: Box::new(err) }
|
||||
}
|
||||
}
|
||||
|
||||
// /// Default error is `InternalServerError`
|
||||
// impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
||||
// fn error_response(&self) -> HttpResponse {
|
||||
// HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Body::Empty)
|
||||
// }
|
||||
// }
|
||||
/// Default error is `InternalServerError`
|
||||
#[cfg(feature="nightly")]
|
||||
default impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Body::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
/// `InternalServerError` for `JsonError`
|
||||
impl ErrorResponse for JsonError {}
|
||||
|
||||
/// A set of errors that can occur during parsing HTTP streams
|
||||
#[derive(Fail, Debug)]
|
||||
|
@ -1,5 +1,9 @@
|
||||
//! Web framework for [Actix](https://github.com/actix/actix)
|
||||
|
||||
#![cfg_attr(feature="nightly", feature(
|
||||
specialization, // for impl ErrorResponse for std::error::Error
|
||||
))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate time;
|
||||
|
Loading…
Reference in New Issue
Block a user