1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-27 10:39:03 +02:00

refactor ResponseError trait

This commit is contained in:
Nikolay Kim
2019-11-26 16:07:39 +06:00
parent 4dc31aac93
commit f73f97353b
11 changed files with 105 additions and 111 deletions

View File

@ -54,15 +54,11 @@ pub enum UrlencodedError {
/// Return `BadRequest` for `UrlencodedError`
impl ResponseError for UrlencodedError {
fn error_response(&self) -> HttpResponse {
fn status_code(&self) -> StatusCode {
match *self {
UrlencodedError::Overflow { .. } => {
HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE)
}
UrlencodedError::UnknownLength => {
HttpResponse::new(StatusCode::LENGTH_REQUIRED)
}
_ => HttpResponse::new(StatusCode::BAD_REQUEST),
UrlencodedError::Overflow { .. } => StatusCode::PAYLOAD_TOO_LARGE,
UrlencodedError::UnknownLength => StatusCode::LENGTH_REQUIRED,
_ => StatusCode::BAD_REQUEST,
}
}
}
@ -106,10 +102,8 @@ pub enum PathError {
/// Return `BadRequest` for `PathError`
impl ResponseError for PathError {
fn error_response(&self) -> HttpResponse {
match *self {
PathError::Deserialize(_) => HttpResponse::new(StatusCode::BAD_REQUEST),
}
fn status_code(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
@ -123,12 +117,8 @@ pub enum QueryPayloadError {
/// Return `BadRequest` for `QueryPayloadError`
impl ResponseError for QueryPayloadError {
fn error_response(&self) -> HttpResponse {
match *self {
QueryPayloadError::Deserialize(_) => {
HttpResponse::new(StatusCode::BAD_REQUEST)
}
}
fn status_code(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
@ -152,12 +142,10 @@ pub enum ReadlinesError {
/// Return `BadRequest` for `ReadlinesError`
impl ResponseError for ReadlinesError {
fn error_response(&self) -> HttpResponse {
fn status_code(&self) -> StatusCode {
match *self {
ReadlinesError::LimitOverflow => {
HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE)
}
_ => HttpResponse::new(StatusCode::BAD_REQUEST),
ReadlinesError::LimitOverflow => StatusCode::PAYLOAD_TOO_LARGE,
_ => StatusCode::BAD_REQUEST,
}
}
}

View File

@ -63,7 +63,7 @@
//! * SSL support with OpenSSL or `native-tls`
//! * Middlewares (`Logger`, `Session`, `CORS`, `DefaultHeaders`)
//! * Supports [Actix actor framework](https://github.com/actix/actix)
//! * Supported Rust version: 1.36 or later
//! * Supported Rust version: 1.39 or later
//!
//! ## Package feature
//!