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
#[derive(Debug, PartialEq)]
pub enum Error {
UnreachableServer,
IndexAlreadyExist,
IndexNotFound,
InvalidIndexUid,
CantInferPrimaryKey,
Unknown(String),
}
impl From<&str> for Error {
fn from(message: &str) -> Error {
match message {
"{\"message\":\"Impossible to create index; index already exists\"}" => Error::IndexAlreadyExist,
"{\"message\":\"Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).\"}" => Error::InvalidIndexUid,
"{\"message\":\"Could not infer a primary key\"}" => Error::CantInferPrimaryKey,
m if m.starts_with("{\"message\":\"Index ") && m.ends_with(" not found\"}") => Error::IndexNotFound,
e => {
Error::Unknown(e.to_string())
},
}
}
}
impl From<minreq::Error> for Error {
fn from(error: minreq::Error) -> Error {
match error {
minreq::Error::IoError(e) if e.kind() == std::io::ErrorKind::ConnectionRefused => {
Error::UnreachableServer
}
e => {
Error::Unknown(format!("{:?}", e))
},
}
}
}