1use std::{error, fmt};
2
3#[derive(Debug)]
4pub enum MultipartError {
5 NoPostMethod,
7 NoContentDisposition,
9 NoContentType,
11 ParseContentType,
13 Boundary,
15 Nested,
17 UnexpectedEof,
19 BufferOverflow,
21 Header(httparse::Error),
23 Payload(PayloadError),
25}
26
27pub type PayloadError = Box<dyn error::Error + Send + Sync>;
28
29impl fmt::Display for MultipartError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match *self {
32 Self::NoPostMethod => f.write_str("Only POST method is allowed for multipart"),
33 Self::NoContentDisposition => f.write_str("No Content-Disposition `form-data` header"),
34 Self::NoContentType => f.write_str("No Content-Type header found"),
35 Self::ParseContentType => f.write_str("Can not parse Content-Type header"),
36 Self::Boundary => f.write_str("Multipart boundary is not found"),
37 Self::Nested => f.write_str("Nested multipart is not supported"),
38 Self::UnexpectedEof => f.write_str("Multipart stream ended early than expected."),
39 Self::BufferOverflow => f.write_str("Multipart parsing internal buffer overflown"),
40 Self::Header(ref e) => fmt::Display::fmt(e, f),
41 Self::Payload(ref e) => fmt::Display::fmt(e, f),
42 }
43 }
44}
45
46impl error::Error for MultipartError {}
47
48impl From<httparse::Error> for MultipartError {
49 fn from(e: httparse::Error) -> Self {
50 Self::Header(e)
51 }
52}
53
54impl From<PayloadError> for MultipartError {
55 fn from(e: PayloadError) -> Self {
56 Self::Payload(e)
57 }
58}