multipart_rs/
error.rs

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
use std::{
    error::Error,
    fmt::{Display, Formatter, Result},
};

#[derive(Debug)]
pub enum MultipartError {
    // Missing Content-Type header
    NoContentType,

    // Invalid boundary
    InvalidBoundary,

    // Invalid Content-Type
    InvalidContentType,

    // Invalid Multipart type
    InvalidMultipartType,

    // Invalid Item header
    InvalidItemHeader,

    // Failed to poll data from the stream
    PollingDataFailed,
}

impl Display for MultipartError {
    fn fmt(&self, f: &mut Formatter) -> Result {
        match self {
            MultipartError::NoContentType => write!(f, "No Content-Type header"),
            MultipartError::InvalidBoundary => write!(f, "Invalid boundary"),
            MultipartError::InvalidContentType => write!(f, "Invalid Content-Type"),
            MultipartError::InvalidMultipartType => write!(f, "Invalid Multipart type"),
            MultipartError::InvalidItemHeader => write!(f, "Invalid Item header"),
            MultipartError::PollingDataFailed => write!(f, "Failed to poll data from the stream"),
        }
    }
}

impl Error for MultipartError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        None
    }
}