multipart_rs/
error.rs

1use std::{
2    error::Error,
3    fmt::{Display, Formatter, Result},
4};
5
6use mediatype::MediaTypeError;
7
8#[derive(Debug)]
9pub enum MultipartError {
10    // Missing Content-Type header
11    NoContentType,
12
13    // Invalid boundary
14    InvalidBoundary,
15
16    // Content-Type parsing error
17    ContentTypeParsingError(MediaTypeError),
18
19    // Invalid Content-Type
20    InvalidContentType,
21
22    // Invalid Multipart type
23    InvalidMultipartType,
24
25    // Invalid Item header
26    InvalidItemHeader,
27
28    // Failed to poll data from the stream
29    PollingDataFailed,
30}
31
32impl Display for MultipartError {
33    fn fmt(&self, f: &mut Formatter) -> Result {
34        match self {
35            MultipartError::NoContentType => write!(f, "No Content-Type header"),
36            MultipartError::InvalidBoundary => write!(f, "Invalid boundary"),
37            MultipartError::InvalidContentType => write!(f, "Invalid Content-Type"),
38            MultipartError::InvalidMultipartType => write!(f, "Invalid Multipart type"),
39            MultipartError::InvalidItemHeader => write!(f, "Invalid Item header"),
40            MultipartError::PollingDataFailed => write!(f, "Failed to poll data from the stream"),
41            MultipartError::ContentTypeParsingError(e) => {
42                write!(f, "Content-Type parsing error: {}", e)
43            }
44        }
45    }
46}
47
48impl Error for MultipartError {
49    fn source(&self) -> Option<&(dyn Error + 'static)> {
50        None
51    }
52}