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
53
54
55
56
57
58
59
60
#[derive(Debug)]
pub enum SlackError {
    ApiError(SlackApiError),
    HttpError(SlackHttpError),
    SystemError(SlackSystemError),
}

impl From<SlackApiError> for SlackError {
    fn from(value: SlackApiError) -> Self {
        SlackError::ApiError(value)
    }
}

impl From<SlackHttpError> for SlackError {
    fn from(value: SlackHttpError) -> Self {
        SlackError::HttpError(value)
    }
}

impl From<SlackSystemError> for SlackError {
    fn from(value: SlackSystemError) -> Self {
        SlackError::SystemError(value)
    }
}

#[derive(Debug)]
pub struct SlackApiError {
    pub status: u16,
    pub errors: Option<Vec<String>>,
    pub warnings: Option<Vec<String>>,
    pub http_response_body: Option<String>,
}

#[derive(Debug)]
pub struct SlackHttpError {
    pub status: u16,
    pub http_response_body: Option<String>,
}

impl SlackHttpError {
    pub fn new(status: u16, http_response_body: String) -> SlackHttpError {
        SlackHttpError {
            status,
            http_response_body: Some(http_response_body),
        }
    }
}

#[derive(Debug)]
pub struct SlackSystemError {
    pub message: Option<String>,
}

impl SlackSystemError {
    pub fn new(message: String) -> SlackSystemError {
        SlackSystemError {
            message: Some(message),
        }
    }
}