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
use std::error::Error;
use std::fmt;
#[repr(u8)]
#[derive(Debug)]
pub enum MindsError {
LoginFailed,
ImageUploadSendError,
ImageUploadServerReject,
ImageUploadInvalidResponse,
PostUploadSendError,
PostUploadServerReject,
PostUploadInvalidResponse,
}
impl fmt::Display for MindsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for MindsError {
fn description(&self) -> &str {
match self {
&MindsError::LoginFailed => "Login has failed",
&MindsError::ImageUploadSendError => "Failed to send request to upload image",
&MindsError::ImageUploadServerReject => "Server rejected upload of image",
&MindsError::ImageUploadInvalidResponse => "Server sent invalid response. Doesn't contain field id",
&MindsError::PostUploadSendError => "Failed to send request to perform text post",
&MindsError::PostUploadServerReject => "Server rejected posting",
&MindsError::PostUploadInvalidResponse => "Server sent invalid response. Doesn't contain field id",
}
}
}