Skip to main content

lichess_api/
error.rs

1#[derive(Debug, thiserror::Error)]
2pub enum Error {
3    #[error("urlencoded serde error: {0}")]
4    UrlEncoded(#[from] serde_urlencoded::ser::Error),
5
6    #[error("http request builder error: {0}")]
7    HttpRequestBuilder(#[from] http::Error),
8
9    #[error("lichess status error: {0}")]
10    LichessStatus(String),
11
12    #[error("page not found error (likely invalid path)")]
13    PageNotFound(),
14
15    #[error("request parameters error: {0}")]
16    RequestParams(String),
17
18    #[error("request error: {0}")]
19    Request(String),
20
21    #[error("response error: {0}")]
22    Response(String),
23
24    #[error("io error: {0}")]
25    IO(#[from] std::io::Error),
26
27    #[error("json serde error: {0}")]
28    Json(#[from] serde_json::Error),
29
30    #[cfg(feature = "oauth")]
31    #[error("oauth error: {error}{}", .error_description.as_ref().map(|d| format!(" ({d})")).unwrap_or_default())]
32    OAuth {
33        /// The cause of the error, e.g. `access_denied` if the user cancelled
34        /// authorization, or `invalid_grant`.
35        error: String,
36        /// The reason the request was rejected, to aid debugging.
37        error_description: Option<String>,
38    },
39
40    #[cfg(feature = "oauth")]
41    #[error("oauth state mismatch (possible cross site request forgery)")]
42    OAuthStateMismatch,
43
44    #[error("unknown error: {0}")]
45    Unknown(String),
46}
47
48pub type Result<T> = std::result::Result<T, Error>;