meilisearch/meilisearch-auth/src/error.rs

37 lines
1.0 KiB
Rust
Raw Normal View History

use std::error::Error;
use meilisearch_types::error::{Code, ErrorCode};
use meilisearch_types::{internal_error, keys, milli};
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),
#[error("Internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>),
}
internal_error!(
AuthControllerError: milli::heed::Error,
std::io::Error,
serde_json::Error,
std::str::Utf8Error
);
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(),
Self::ApiKeyNotFound(_) => Code::ApiKeyNotFound,
2022-05-25 16:32:47 +08:00
Self::ApiKeyAlreadyExists(_) => Code::ApiKeyAlreadyExists,
Self::Internal(_) => Code::Internal,
}
}
}