2021-06-24 16:53:20 +02:00
|
|
|
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.")]
|
2021-06-24 16:53:20 +02:00
|
|
|
MissingAuthorizationHeader,
|
2021-11-03 14:25:49 +01:00
|
|
|
#[error("The provided API key is invalid.")]
|
2021-06-24 16:53:20 +02:00
|
|
|
InvalidToken(String),
|
|
|
|
// Triggered on configuration error.
|
2021-11-03 14:25:49 +01:00
|
|
|
#[error("An internal error has occurred. `Irretrievable state`.")]
|
2021-06-24 16:53:20 +02:00
|
|
|
IrretrievableState,
|
2021-11-03 14:25:49 +01:00
|
|
|
#[error("An internal error has occurred. `Unknown authentication policy`.")]
|
2021-06-24 16:53:20 +02:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|