use thiserror::Error;
#[derive(Debug, Error)]
pub enum IdentityError {
#[error("http error: {0}")]
Http(String),
#[error("deserialization error: {0}")]
Deserialization(String),
#[error("validation error: {0}")]
Validation(String),
#[error("configuration error: {0}")]
Configuration(String),
#[error("key not found: {0}")]
KeyNotFound(String),
#[error("token endpoint error {error:?}{}: HTTP {status}", .description.as_deref().map(|d| format!(": {d}")).unwrap_or_default())]
TokenEndpoint {
error: String,
description: Option<String>,
error_uri: Option<String>,
status: u16,
},
#[error("userinfo endpoint error: HTTP {status}{}", .www_authenticate.as_deref().map(|w| format!(": {w}")).unwrap_or_default())]
UserInfo {
status: u16,
www_authenticate: Option<String>,
body: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_messages() {
assert_eq!(
IdentityError::Validation("token expired".into()).to_string(),
"validation error: token expired"
);
assert_eq!(
IdentityError::KeyNotFound("abc".into()).to_string(),
"key not found: abc"
);
}
#[test]
fn is_std_error() {
fn assert_error<E: std::error::Error>(_: &E) {}
assert_error(&IdentityError::Http("boom".into()));
}
}