| 1 | pub type Result<T> = std::result::Result<T, Error>; |
| 2 | |
| 3 | #[derive(Debug, thiserror::Error)] |
| 4 | pub enum Error { |
| 5 | #[error(transparent)] |
| 6 | Graph(#[from] graph::Error), |
| 7 | #[error(transparent)] |
| 8 | Store(#[from] store::Error), |
| 9 | #[error("cannot write the file: {0}")] |
| 10 | Io(#[from] std::io::Error), |
| 11 | #[error("folder service: {0}")] |
| 12 | Folders(String), |
| 13 | #[error("unknown conversation {0}")] |
| 14 | UnknownConversation(String), |
| 15 | #[error("GIFs are disabled by the organization")] |
| 16 | GifsDisabled, |
| 17 | #[error("{0} is not supported yet")] |
| 18 | Unsupported(&'static str), |
| 19 | #[error("banner image: {0}")] |
| 20 | BannerImage(&'static str), |
| 21 | /// The post is out; only its banner card could not be set. |
| 22 | #[error("posted without the banner")] |
| 23 | PostedWithoutBanner, |
| 24 | } |
| 25 | |
| 26 | impl From<chatsvc::Error> for Error { |
| 27 | fn from(error: chatsvc::Error) -> Self { |
| 28 | match error { |
| 29 | chatsvc::Error::Session(inner) => Error::Graph(graph::Error::Session(inner)), |
| 30 | chatsvc::Error::GifsDisabled => Error::GifsDisabled, |
| 31 | chatsvc::Error::AccessDenied => Error::Graph(graph::Error::NotAMember), |
| 32 | other => Error::Folders(other.to_string()), |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #[cfg(test)] |
| 38 | mod tests { |
| 39 | use super::*; |
| 40 | |
| 41 | #[test] |
| 42 | fn access_denied_is_not_a_member() { |
| 43 | let error = Error::from(chatsvc::Error::AccessDenied); |
| 44 | assert!(matches!(error, Error::Graph(graph::Error::NotAMember))); |
| 45 | } |
| 46 | } |