mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 18:34:36 +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
|
# openssl
|
||||||
alpn = ["openssl", "openssl/v102", "openssl/v110", "tokio-openssl"]
|
alpn = ["openssl", "openssl/v102", "openssl/v110", "tokio-openssl"]
|
||||||
|
|
||||||
|
# nightly
|
||||||
|
nightly = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
failure = "0.1"
|
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::string::FromUtf8Error;
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
|
|
||||||
|
#[cfg(feature="nightly")]
|
||||||
|
use std::error::Error as StdError;
|
||||||
|
|
||||||
use cookie;
|
use cookie;
|
||||||
use httparse;
|
use httparse;
|
||||||
use failure::Fail;
|
use failure::Fail;
|
||||||
use http2::Error as Http2Error;
|
use http2::Error as Http2Error;
|
||||||
use http::{header, StatusCode, Error as HttpError};
|
use http::{header, StatusCode, Error as HttpError};
|
||||||
use http_range::HttpRangeParseError;
|
use http_range::HttpRangeParseError;
|
||||||
|
use serde_json::error::Error as JsonError;
|
||||||
|
|
||||||
// re-exports
|
// re-exports
|
||||||
pub use cookie::{ParseError as CookieParseError};
|
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 {
|
impl<T: ErrorResponse> From<T> for Error {
|
||||||
fn from(err: T) -> Error {
|
fn from(err: T) -> Error {
|
||||||
Error { cause: Box::new(err) }
|
Error { cause: Box::new(err) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Default error is `InternalServerError`
|
/// Default error is `InternalServerError`
|
||||||
// impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
#[cfg(feature="nightly")]
|
||||||
// fn error_response(&self) -> HttpResponse {
|
default impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
||||||
// HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Body::Empty)
|
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
|
/// A set of errors that can occur during parsing HTTP streams
|
||||||
#[derive(Fail, Debug)]
|
#[derive(Fail, Debug)]
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
//! Web framework for [Actix](https://github.com/actix/actix)
|
//! Web framework for [Actix](https://github.com/actix/actix)
|
||||||
|
|
||||||
|
#![cfg_attr(feature="nightly", feature(
|
||||||
|
specialization, // for impl ErrorResponse for std::error::Error
|
||||||
|
))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
Loading…
Reference in New Issue
Block a user