1use crate::api_result::ApiError;
2use reqwest::header::InvalidHeaderValue;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum Error {
7 #[error(transparent)]
8 Api(#[from] ApiError),
9 #[error(transparent)]
10 Request(#[from] reqwest::Error),
11 #[error(transparent)]
12 Url(#[from] url::ParseError),
13 #[error(transparent)]
14 Json(#[from] serde_json::Error),
15 #[error("Invalid Authorization header value: {_0}")]
16 InvalidAuthorizationHeader(InvalidHeaderValue),
17 #[cfg(feature = "oauth2")]
18 #[error(transparent)]
19 Oauth2TokenError(
20 #[from]
21 oauth2::RequestTokenError<
22 oauth2::reqwest::Error<reqwest::Error>,
23 oauth2::basic::BasicErrorResponse,
24 >,
25 ),
26 #[cfg(feature = "oauth2")]
27 #[error(transparent)]
28 Oauth2RevocationError(
29 #[from]
30 oauth2::RequestTokenError<
31 oauth2::reqwest::Error<reqwest::Error>,
32 oauth2::basic::BasicRevocationErrorResponse,
33 >,
34 ),
35 #[cfg(feature = "oauth2")]
36 #[error("No refresh token found. Try using the `offline.access` scope")]
37 NoRefreshToken,
38 #[error("Other: {_0}")]
39 Custom(String),
40}
41
42impl Error {
43 pub fn custom(message: impl ToString) -> Self {
44 Self::Custom(message.to_string())
45 }
46}
47
48pub type Result<T, E = Error> = std::result::Result<T, E>;