use axum::http::StatusCode;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OAuthErrorCode {
InvalidRequest,
InvalidClient,
InvalidGrant,
UnauthorizedClient,
UnsupportedGrantType,
InvalidScope,
InvalidToken,
AccessDenied,
ServerError,
TemporarilyUnavailable,
InvalidClientMetadata,
AuthenticationFailed,
RegistrationFailed,
UsernameUnavailable,
EmailExists,
ExpiredChallenge,
InvalidCredential,
LinkFailed,
InvalidTarget,
NotFound,
}
impl OAuthErrorCode {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::InvalidRequest => "invalid_request",
Self::InvalidClient => "invalid_client",
Self::InvalidGrant => "invalid_grant",
Self::UnauthorizedClient => "unauthorized_client",
Self::UnsupportedGrantType => "unsupported_grant_type",
Self::InvalidScope => "invalid_scope",
Self::InvalidToken => "invalid_token",
Self::AccessDenied => "access_denied",
Self::ServerError => "server_error",
Self::TemporarilyUnavailable => "temporarily_unavailable",
Self::InvalidClientMetadata => "invalid_client_metadata",
Self::AuthenticationFailed => "authentication_failed",
Self::RegistrationFailed => "registration_failed",
Self::UsernameUnavailable => "username_unavailable",
Self::EmailExists => "email_exists",
Self::ExpiredChallenge => "expired_challenge",
Self::InvalidCredential => "invalid_credential",
Self::LinkFailed => "link_failed",
Self::InvalidTarget => "invalid_target",
Self::NotFound => "not_found",
}
}
#[must_use]
pub const fn default_status(self) -> StatusCode {
match self {
Self::InvalidRequest
| Self::InvalidGrant
| Self::UnauthorizedClient
| Self::UnsupportedGrantType
| Self::InvalidScope
| Self::InvalidClientMetadata
| Self::ExpiredChallenge
| Self::InvalidCredential
| Self::LinkFailed
| Self::InvalidTarget
| Self::RegistrationFailed => StatusCode::BAD_REQUEST,
Self::InvalidClient
| Self::AccessDenied
| Self::AuthenticationFailed
| Self::InvalidToken => StatusCode::UNAUTHORIZED,
Self::UsernameUnavailable | Self::EmailExists => StatusCode::CONFLICT,
Self::NotFound => StatusCode::NOT_FOUND,
Self::ServerError => StatusCode::INTERNAL_SERVER_ERROR,
Self::TemporarilyUnavailable => StatusCode::SERVICE_UNAVAILABLE,
}
}
}