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

26 lines
1.0 KiB
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,
#[error("Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.")]
MissingMasterKey,
}
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,
AuthenticationError::MissingMasterKey => Code::MissingMasterKey,
}
}
}