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
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, Error)]
pub enum Error {
#[error("failed API")]
API { message: String, is_retryable: bool },
#[error("failed for other reasons")]
Other { message: String, is_retryable: bool },
}
impl Error {
#[inline]
#[must_use]
pub fn message(&self) -> String {
match self {
Error::API { message, .. } | Error::Other { message, .. } => message.clone(),
}
}
#[inline]
#[must_use]
pub fn is_retryable(&self) -> bool {
match self {
Error::API { is_retryable, .. } | Error::Other { is_retryable, .. } => *is_retryable,
}
}
#[inline]
#[must_use]
pub fn contains(&self, s: &str) -> bool {
self.message().contains(s)
}
}