MeiliSearch/meilisearch-auth/src/error.rs

34 lines
961 B
Rust
Raw Normal View History

use std::error::Error;
use meilisearch_types::error::{Code, ErrorCode};
2023-01-11 12:33:56 +01:00
use meilisearch_types::internal_error;
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 14:11:56 +02:00
#[error("`uid` field value `{0}` is already an existing API key.")]
2022-05-25 10:32:47 +02:00
ApiKeyAlreadyExists(String),
#[error("Internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>),
}
internal_error!(
2022-10-17 15:11:35 +02:00
AuthControllerError: meilisearch_types::milli::heed::Error,
std::io::Error,
serde_json::Error,
std::str::Utf8Error
);
impl ErrorCode for AuthControllerError {
fn error_code(&self) -> Code {
match self {
Self::ApiKeyNotFound(_) => Code::ApiKeyNotFound,
2022-05-25 10:32:47 +02:00
Self::ApiKeyAlreadyExists(_) => Code::ApiKeyAlreadyExists,
Self::Internal(_) => Code::Internal,
}
}
}