mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 00:50:20 +02:00
added JsonBody future
This commit is contained in:
41
src/error.rs
41
src/error.rs
@@ -10,6 +10,7 @@ use std::error::Error as StdError;
|
||||
use cookie;
|
||||
use httparse;
|
||||
use failure::Fail;
|
||||
use futures::Canceled;
|
||||
use http2::Error as Http2Error;
|
||||
use http::{header, StatusCode, Error as HttpError};
|
||||
use http::uri::InvalidUriBytes;
|
||||
@@ -110,6 +111,9 @@ impl ResponseError for io::Error {
|
||||
/// `InternalServerError` for `InvalidHeaderValue`
|
||||
impl ResponseError for header::InvalidHeaderValue {}
|
||||
|
||||
/// `InternalServerError` for `futures::Canceled`
|
||||
impl ResponseError for Canceled {}
|
||||
|
||||
/// Internal error
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display="Unexpected task frame")]
|
||||
@@ -393,6 +397,43 @@ impl From<PayloadError> for UrlencodedError {
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of errors that can occur during parsing json payloads
|
||||
#[derive(Fail, Debug)]
|
||||
pub enum JsonPayloadError {
|
||||
/// Payload size is bigger than 256k
|
||||
#[fail(display="Payload size is bigger than 256k")]
|
||||
Overflow,
|
||||
/// Content type error
|
||||
#[fail(display="Content type error")]
|
||||
ContentType,
|
||||
/// Deserialize error
|
||||
#[fail(display="Json deserialize error")]
|
||||
Deserialize(JsonError),
|
||||
/// Payload error
|
||||
#[fail(display="Error that occur during reading payload")]
|
||||
Payload(PayloadError),
|
||||
}
|
||||
|
||||
/// Return `BadRequest` for `UrlencodedError`
|
||||
impl ResponseError for JsonPayloadError {
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::new(StatusCode::BAD_REQUEST, Body::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PayloadError> for JsonPayloadError {
|
||||
fn from(err: PayloadError) -> JsonPayloadError {
|
||||
JsonPayloadError::Payload(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonError> for JsonPayloadError {
|
||||
fn from(err: JsonError) -> JsonPayloadError {
|
||||
JsonPayloadError::Deserialize(err)
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors which can occur when attempting to interpret a segment string as a
|
||||
/// valid path segment.
|
||||
#[derive(Fail, Debug, PartialEq)]
|
||||
|
Reference in New Issue
Block a user