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

26 lines
931 B
Rust
Raw Normal View History

use meilisearch_error::{Code, ErrorCode};
#[derive(Debug, thiserror::Error)]
pub enum AuthenticationError {
2021-11-03 14:25:49 +01:00
#[error("The X-MEILI-API-KEY header is missing.")]
MissingAuthorizationHeader,
2021-11-03 14:25:49 +01:00
#[error("The provided API key is invalid.")]
InvalidToken(String),
// Triggered on configuration error.
2021-11-03 14:25:49 +01:00
#[error("An internal error has occurred. `Irretrievable state`.")]
IrretrievableState,
2021-11-03 14:25:49 +01:00
#[error("An internal error has occurred. `Unknown authentication policy`.")]
UnknownPolicy,
}
impl ErrorCode for AuthenticationError {
fn error_code(&self) -> Code {
match self {
AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader,
AuthenticationError::InvalidToken(_) => Code::InvalidToken,
AuthenticationError::IrretrievableState => Code::Internal,
AuthenticationError::UnknownPolicy => Code::Internal,
}
}
}