rs_identity_model/discovery/
error.rs1use crate::IdentityError;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum DiscoveryError {
10 #[error("unexpected HTTP status {status} from {endpoint}")]
12 UnexpectedStatus { status: u16, endpoint: String },
13 #[error("invalid discovery document from {endpoint}: {reason}")]
15 InvalidJson { endpoint: String, reason: String },
16 #[error("discovery document from {endpoint} is missing required field(s): {}", .fields.join(", "))]
18 MissingFields {
19 fields: Vec<String>,
20 endpoint: String,
21 },
22 #[error("issuer mismatch: requested {requested:?} but document declares {actual:?}")]
24 IssuerMismatch { requested: String, actual: String },
25 #[error("issuer {issuer:?} must use https (enable allow_http for development)")]
27 HttpsRequired { issuer: String },
28 #[error(transparent)]
30 Other(#[from] IdentityError),
31}
32
33impl From<DiscoveryError> for IdentityError {
34 fn from(error: DiscoveryError) -> Self {
35 match error {
36 DiscoveryError::Other(error) => error,
37 error @ DiscoveryError::UnexpectedStatus { .. } => Self::Http(error.to_string()),
38 error @ DiscoveryError::InvalidJson { .. } => Self::Deserialization(error.to_string()),
39 error => Self::Validation(error.to_string()),
40 }
41 }
42}