#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{code}: {detail}")]
pub struct SignatureError {
pub code: &'static str,
pub detail: String,
}
impl SignatureError {
pub fn new(code: &'static str, detail: impl Into<String>) -> Self {
Self {
code,
detail: detail.into(),
}
}
pub fn header_value(&self) -> String {
format!("error={}", self.code)
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{code}: {detail}")]
pub struct TokenError {
pub code: &'static str,
pub detail: String,
}
impl TokenError {
pub fn new(code: &'static str, detail: impl Into<String>) -> Self {
Self {
code,
detail: detail.into(),
}
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Signature(#[from] SignatureError),
#[error(transparent)]
Token(#[from] TokenError),
#[error("invalid key: {0}")]
Key(String),
#[error("url: {0}")]
Url(String),
#[error("discovery: {0}")]
Discovery(String),
#[error("http: {0}")]
Http(String),
#[error("invalid: {0}")]
Invalid(String),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;