#[derive(Debug)]
pub enum Error {
BadRequest,
AuthenticationFailed(AuthenticationFailedError),
InternalError,
BadGateway(reqwest::Error),
}
impl From<AuthenticationFailedError> for Error {
fn from(err: AuthenticationFailedError) -> Self {
Self::AuthenticationFailed(err)
}
}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Self::BadGateway(err)
}
}
impl From<Error> for http::StatusCode {
fn from(e: Error) -> Self {
use Error::*;
match e {
BadRequest => http::StatusCode::BAD_REQUEST,
AuthenticationFailed(_) => http::StatusCode::UNAUTHORIZED,
InternalError => http::StatusCode::INTERNAL_SERVER_ERROR,
BadGateway(_) => http::StatusCode::BAD_GATEWAY,
}
}
}
#[derive(Debug)]
pub enum AuthenticationFailedError {
ClaimValidationError,
JwsDecodeError,
}
impl From<base64::DecodeError> for AuthenticationFailedError {
fn from(err: base64::DecodeError) -> Self {
log::warn!("Invalid ID token: {:?}", err);
Self::JwsDecodeError
}
}
impl From<serde_json::Error> for AuthenticationFailedError {
fn from(err: serde_json::Error) -> Self {
log::warn!("Invalid ID token: {:?}", err);
Self::JwsDecodeError
}
}