connpass_rs/
errors.rs

1//! Provides error types using in this crate.
2
3use thiserror::Error;
4
5/// General errors for this crate.
6#[derive(Debug, Error)]
7#[error(transparent)]
8pub enum ConnpassCliError {
9    /// Errors around validation.
10    Validation(ValidationError),
11    /// Errors around HTTP connection including JSON decoding, status code, etc.
12    HttpResponse(HttpResponseError),
13}
14
15/// Represents errors around validation.
16#[derive(Debug, Error)]
17pub enum ValidationError {
18    /// Uses when a value is out of the specific range.
19    #[error("{msg}")]
20    OutOfRange { msg: String },
21    /// Uses when unexpected token is passed to a value.
22    #[error("{msg}")]
23    InvalidToken { msg: String },
24}
25
26/// Represents errors around HTTP connection.
27#[derive(Debug, Error)]
28pub enum HttpResponseError {
29    /// Uses when an error cannot be categorised any more.
30    #[error("{0}")]
31    Various(String),
32    /// Uses when decoding JSON failed.
33    #[error("{0}")]
34    JsonDecode(String),
35    /// For representing HTTP status code 403.
36    #[error("Forbidden")]
37    Forbidden,
38    /// For representing HTTP status code 500.
39    #[error("Internal Server Error")]
40    InternalServerError,
41    /// For representing HTTP status code 503.
42    #[error("Service Unavailable")]
43    ServiceUnavailable,
44    /// Convert from the errors from reqwest crate to the domain specific error type.
45    #[error(transparent)]
46    ReqwestError(#[from] reqwest::Error),
47}
48
49pub type ConnpassResult<T> = core::result::Result<T, ConnpassCliError>;