#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum MiddlewareError {
Unauthenticated(String),
HttpChallenge {
status: u16,
www_authenticate: String,
},
Forbidden(String),
Internal(String),
}
impl MiddlewareError {
pub(crate) fn precedence(&self) -> u8 {
match self {
Self::Forbidden(_) => 3,
Self::HttpChallenge { .. } => 2,
Self::Unauthenticated(_) => 1,
Self::Internal(_) => 0, }
}
pub fn http_status(&self) -> u16 {
match self {
Self::Unauthenticated(_) | Self::HttpChallenge { .. } => 401,
Self::Forbidden(_) => 403,
Self::Internal(_) => 500,
}
}
}