1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use actix_web::error::{ParseError, PayloadError};
use actix_web::http::StatusCode;
use actix_web::{HttpResponse, ResponseError};
use derive_more::{Display, From};
#[derive(Debug, Display, From)]
pub enum MultipartError {
#[display(fmt = "No Content-type header found")]
NoContentType,
#[display(fmt = "Can not parse Content-Type header")]
ParseContentType,
#[display(fmt = "Multipart boundary is not found")]
Boundary,
#[display(fmt = "Nested multipart is not supported")]
Nested,
#[display(fmt = "Multipart stream is incomplete")]
Incomplete,
#[display(fmt = "{}", _0)]
Parse(ParseError),
#[display(fmt = "{}", _0)]
Payload(PayloadError),
#[display(fmt = "Multipart stream is not consumed")]
NotConsumed,
}
impl ResponseError for MultipartError {
fn error_response(&self) -> HttpResponse {
HttpResponse::new(StatusCode::BAD_REQUEST)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_multipart_error() {
let resp: HttpResponse = MultipartError::Boundary.error_response();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
}