From fce8dd275ab0c86559a098af3c2d2b58ef17ff1f Mon Sep 17 00:00:00 2001 From: Douman Date: Sat, 2 Jun 2018 22:20:22 +0300 Subject: [PATCH 1/2] Specialize ResponseError for PayloadError Closes #257 --- src/error.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 481cf326..174530ca 100644 --- a/src/error.rs +++ b/src/error.rs @@ -294,7 +294,14 @@ impl From for PayloadError { } /// `InternalServerError` for `PayloadError` -impl ResponseError for PayloadError {} +impl ResponseError for PayloadError { + fn error_response(&self) -> HttpResponse { + match *self { + PayloadError::Overflow => HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE), + _ => HttpResponse::new(StatusCode::BAD_REQUEST) + } + } +} /// Return `BadRequest` for `cookie::ParseError` impl ResponseError for cookie::ParseError { From 2a9b57f489fa82142d3b7072fa86e8b80c79f18b Mon Sep 17 00:00:00 2001 From: Douman Date: Sat, 2 Jun 2018 22:27:43 +0300 Subject: [PATCH 2/2] Correct docstring --- src/error.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 174530ca..6bb94af5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -293,7 +293,10 @@ impl From for PayloadError { } } -/// `InternalServerError` for `PayloadError` +/// `PayloadError` returns two possible results: +/// +/// - `Overflow` returns `PayloadTooLarge` +/// - Other errors returns `BadRequest` impl ResponseError for PayloadError { fn error_response(&self) -> HttpResponse { match *self {