MeiliSearch/meilisearch-http/src/extractors/authentication/error.rs

23 lines
804 B
Rust
Raw Normal View History

use meilisearch_types::error::{Code, ErrorCode};
#[derive(Debug, thiserror::Error)]
pub enum AuthenticationError {
#[error("The Authorization header is missing. It must use the bearer authorization method.")]
MissingAuthorizationHeader,
2021-11-03 14:25:49 +01:00
#[error("The provided API key is invalid.")]
2022-03-07 15:15:51 +01:00
InvalidToken,
// Triggered on configuration error.
2021-11-03 14:25:49 +01:00
#[error("An internal error has occurred. `Irretrievable state`.")]
IrretrievableState,
}
impl ErrorCode for AuthenticationError {
fn error_code(&self) -> Code {
match self {
AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader,
2022-03-07 15:15:51 +01:00
AuthenticationError::InvalidToken => Code::InvalidToken,
AuthenticationError::IrretrievableState => Code::Internal,
}
}
}