use std::io;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("OAuth2 error: {error} - {description}")]
OAuth {
error: String,
description: String,
},
#[error("Token expired")]
TokenExpired,
#[error("No refresh token available")]
NoRefreshToken,
#[error("Invalid token response: {0}")]
InvalidResponse(String),
#[error("Authorization timed out after {0} seconds")]
Timeout(u64),
#[error("User denied authorization")]
AccessDenied,
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("URL error: {0}")]
UrlError(#[from] url::ParseError),
}
impl Error {
#[must_use]
pub fn oauth_error(error: impl Into<String>, description: impl Into<String>) -> Self {
Self::OAuth {
error: error.into(),
description: description.into(),
}
}
}