2022-06-06 12:38:46 +02:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2021-06-24 16:53:20 +02:00
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum AuthenticationError {
|
2021-11-08 18:31:27 +01:00
|
|
|
#[error("The Authorization header is missing. It must use the bearer authorization method.")]
|
2021-06-24 16:53:20 +02:00
|
|
|
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,
|
2021-06-24 16:53:20 +02:00
|
|
|
// 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,
|
2022-10-18 10:48:45 +05:30
|
|
|
#[error("Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.")]
|
|
|
|
MissingMasterKey,
|
2021-06-24 16:53:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2021-06-24 16:53:20 +02:00
|
|
|
AuthenticationError::IrretrievableState => Code::Internal,
|
2022-10-18 10:48:45 +05:30
|
|
|
AuthenticationError::MissingMasterKey => Code::MissingMasterKey,
|
2021-06-24 16:53:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|