1use derive_more::{Display, From};
3use ntex::http::error::{DecodeError, PayloadError};
4use ntex::http::StatusCode;
5use ntex::web::error::{DefaultError, WebResponseError};
6
7#[derive(Debug, Display, From)]
9pub enum MultipartError {
10 #[display(fmt = "No Content-type header found")]
12 NoContentType,
13 #[display(fmt = "Can not parse Content-Type header")]
15 ParseContentType,
16 #[display(fmt = "Multipart boundary is not found")]
18 Boundary,
19 #[display(fmt = "Nested multipart is not supported")]
21 Nested,
22 #[display(fmt = "Multipart stream is incomplete")]
24 Incomplete,
25 #[display(fmt = "{}", _0)]
27 Decode(DecodeError),
28 #[display(fmt = "{}", _0)]
30 Payload(PayloadError),
31 #[display(fmt = "Multipart stream is not consumed")]
33 NotConsumed,
34}
35
36impl std::error::Error for MultipartError {}
37
38impl WebResponseError<DefaultError> for MultipartError {
40 fn status_code(&self) -> StatusCode {
41 StatusCode::BAD_REQUEST
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48 use ntex::web::test::TestRequest;
49 use ntex::web::HttpResponse;
50
51 #[test]
52 fn test_multipart_error() {
53 let req = TestRequest::default().to_http_request();
54 let resp: HttpResponse = MultipartError::Boundary.error_response(&req);
55 assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
56 }
57}