2021-11-09 01:31:27 +08:00
|
|
|
use std::error::Error;
|
|
|
|
|
2022-06-06 18:38:46 +08:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2022-10-18 00:57:23 +08:00
|
|
|
use meilisearch_types::{internal_error, keys};
|
2021-11-09 01:31:27 +08:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, AuthControllerError>;
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum AuthControllerError {
|
|
|
|
#[error("API key `{0}` not found.")]
|
|
|
|
ApiKeyNotFound(String),
|
2022-06-01 20:11:56 +08:00
|
|
|
#[error("`uid` field value `{0}` is already an existing API key.")]
|
2022-05-25 16:32:47 +08:00
|
|
|
ApiKeyAlreadyExists(String),
|
2022-10-12 22:10:28 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
ApiKey(#[from] keys::Error),
|
2021-11-09 01:31:27 +08:00
|
|
|
#[error("Internal error: {0}")]
|
|
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
|
|
|
}
|
|
|
|
|
2021-12-06 22:45:41 +08:00
|
|
|
internal_error!(
|
2022-10-17 21:11:35 +08:00
|
|
|
AuthControllerError: meilisearch_types::milli::heed::Error,
|
2021-12-06 22:45:41 +08:00
|
|
|
std::io::Error,
|
|
|
|
serde_json::Error,
|
|
|
|
std::str::Utf8Error
|
|
|
|
);
|
2021-11-09 01:31:27 +08:00
|
|
|
|
|
|
|
impl ErrorCode for AuthControllerError {
|
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
2022-10-12 22:10:28 +08:00
|
|
|
Self::ApiKey(e) => e.error_code(),
|
2021-11-09 01:31:27 +08:00
|
|
|
Self::ApiKeyNotFound(_) => Code::ApiKeyNotFound,
|
2022-05-25 16:32:47 +08:00
|
|
|
Self::ApiKeyAlreadyExists(_) => Code::ApiKeyAlreadyExists,
|
2021-11-09 01:31:27 +08:00
|
|
|
Self::Internal(_) => Code::Internal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|