actix_xml/
error.rs

1use actix_web::error::PayloadError;
2use actix_web::http::StatusCode;
3use actix_web::{HttpResponse, ResponseError};
4use quick_xml::DeError as XMLError;
5use thiserror::Error;
6
7/// A set of errors that can occur during parsing xml payloads
8#[derive(Debug, Error)]
9pub enum XMLPayloadError {
10    /// Payload size is bigger than allowed. (default: 32kB)
11    #[error("Xml payload size is bigger than allowed")]
12    Overflow,
13    /// Content type error
14    #[error("Content type error")]
15    ContentType,
16    /// Deserialize error
17    #[error("Xml deserialize error: {0}")]
18    Deserialize(#[from] XMLError),
19    /// Payload error
20    #[error("Error that occur during reading payload: {0}")]
21    Payload(#[from] PayloadError),
22}
23
24impl ResponseError for XMLPayloadError {
25    fn error_response(&self) -> actix_web::HttpResponse {
26        match *self {
27            XMLPayloadError::Overflow => HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE),
28            _ => HttpResponse::new(StatusCode::BAD_REQUEST),
29        }
30    }
31}