mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 16:55:08 +02:00
Implement std::error::Error
for our custom errors
For allowing a more ergonomic use and better integration on the ecosystem, this adds the `std::error::Error` `impl` for our custom errors. We intent to drop this hand made code once `derive_more` finishes the addition of the Error derive support[1]. Until that is available, we need to live with that. 1. https://github.com/JelteF/derive_more/issues/92 Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
This commit is contained in:
12
src/error.rs
12
src/error.rs
@ -21,6 +21,8 @@ pub enum UrlGenerationError {
|
||||
ParseError(UrlParseError),
|
||||
}
|
||||
|
||||
impl std::error::Error for UrlGenerationError {}
|
||||
|
||||
/// `InternalServerError` for `UrlGeneratorError`
|
||||
impl ResponseError for UrlGenerationError {}
|
||||
|
||||
@ -51,6 +53,8 @@ pub enum UrlencodedError {
|
||||
Payload(PayloadError),
|
||||
}
|
||||
|
||||
impl std::error::Error for UrlencodedError {}
|
||||
|
||||
/// Return `BadRequest` for `UrlencodedError`
|
||||
impl ResponseError for UrlencodedError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
@ -79,6 +83,8 @@ pub enum JsonPayloadError {
|
||||
Payload(PayloadError),
|
||||
}
|
||||
|
||||
impl std::error::Error for JsonPayloadError {}
|
||||
|
||||
/// Return `BadRequest` for `JsonPayloadError`
|
||||
impl ResponseError for JsonPayloadError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
@ -99,6 +105,8 @@ pub enum PathError {
|
||||
Deserialize(serde::de::value::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for PathError {}
|
||||
|
||||
/// Return `BadRequest` for `PathError`
|
||||
impl ResponseError for PathError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
@ -114,6 +122,8 @@ pub enum QueryPayloadError {
|
||||
Deserialize(serde::de::value::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for QueryPayloadError {}
|
||||
|
||||
/// Return `BadRequest` for `QueryPayloadError`
|
||||
impl ResponseError for QueryPayloadError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
@ -139,6 +149,8 @@ pub enum ReadlinesError {
|
||||
ContentTypeError(ContentTypeError),
|
||||
}
|
||||
|
||||
impl std::error::Error for ReadlinesError {}
|
||||
|
||||
/// Return `BadRequest` for `ReadlinesError`
|
||||
impl ResponseError for ReadlinesError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
|
Reference in New Issue
Block a user