mailledger_oauth/
error.rs1use std::io;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error("I/O error: {0}")]
13 Io(#[from] io::Error),
14
15 #[error("HTTP error: {0}")]
17 Http(#[from] reqwest::Error),
18
19 #[error("JSON error: {0}")]
21 Json(#[from] serde_json::Error),
22
23 #[error("OAuth2 error: {error} - {description}")]
25 OAuth {
26 error: String,
28 description: String,
30 },
31
32 #[error("Token expired")]
34 TokenExpired,
35
36 #[error("No refresh token available")]
38 NoRefreshToken,
39
40 #[error("Invalid token response: {0}")]
42 InvalidResponse(String),
43
44 #[error("Authorization timed out after {0} seconds")]
46 Timeout(u64),
47
48 #[error("User denied authorization")]
50 AccessDenied,
51
52 #[error("Invalid configuration: {0}")]
54 InvalidConfig(String),
55
56 #[error("URL error: {0}")]
58 UrlError(#[from] url::ParseError),
59}
60
61impl Error {
62 #[must_use]
64 pub fn oauth_error(error: impl Into<String>, description: impl Into<String>) -> Self {
65 Self::OAuth {
66 error: error.into(),
67 description: description.into(),
68 }
69 }
70}