use crate::IdentityError;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum DiscoveryError {
#[error("unexpected HTTP status {status} from {endpoint}")]
UnexpectedStatus { status: u16, endpoint: String },
#[error("invalid discovery document from {endpoint}: {reason}")]
InvalidJson { endpoint: String, reason: String },
#[error("discovery document from {endpoint} is missing required field(s): {}", .fields.join(", "))]
MissingFields {
fields: Vec<String>,
endpoint: String,
},
#[error("issuer mismatch: requested {requested:?} but document declares {actual:?}")]
IssuerMismatch { requested: String, actual: String },
#[error("issuer {issuer:?} must use https (enable allow_http for development)")]
HttpsRequired { issuer: String },
#[error(transparent)]
Other(#[from] IdentityError),
}
impl From<DiscoveryError> for IdentityError {
fn from(error: DiscoveryError) -> Self {
match error {
DiscoveryError::Other(error) => error,
error @ DiscoveryError::UnexpectedStatus { .. } => Self::Http(error.to_string()),
error @ DiscoveryError::InvalidJson { .. } => Self::Deserialization(error.to_string()),
error => Self::Validation(error.to_string()),
}
}
}