mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
ee7970f603
- Add API keys in snapshots - Add API keys in dumps - Rename action indexes.add to indexes.create - fix QA #1979 fix #1979 fix #1995 fix #2001 fix #2003 related to #1890
47 lines
1.9 KiB
Rust
47 lines
1.9 KiB
Rust
use std::error::Error;
|
|
|
|
use meilisearch_error::ErrorCode;
|
|
use meilisearch_error::{internal_error, Code};
|
|
use serde_json::Value;
|
|
|
|
pub type Result<T> = std::result::Result<T, AuthControllerError>;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum AuthControllerError {
|
|
#[error("`{0}` field is mandatory.")]
|
|
MissingParameter(&'static str),
|
|
#[error("actions field value `{0}` is invalid. It should be an array of string representing action names.")]
|
|
InvalidApiKeyActions(Value),
|
|
#[error("indexes field value `{0}` is invalid. It should be an array of string representing index names.")]
|
|
InvalidApiKeyIndexes(Value),
|
|
#[error("expiresAt field value `{0}` is invalid. It should be in ISO-8601 format to represents a date or datetime in the future or specified as a null value. e.g. 'YYYY-MM-DD' or 'YYYY-MM-DDTHH:MM:SS'.")]
|
|
InvalidApiKeyExpiresAt(Value),
|
|
#[error("description field value `{0}` is invalid. It should be a string or specified as a null value.")]
|
|
InvalidApiKeyDescription(Value),
|
|
#[error("API key `{0}` not found.")]
|
|
ApiKeyNotFound(String),
|
|
#[error("Internal error: {0}")]
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
|
}
|
|
|
|
internal_error!(
|
|
AuthControllerError: heed::Error,
|
|
std::io::Error,
|
|
serde_json::Error,
|
|
std::str::Utf8Error
|
|
);
|
|
|
|
impl ErrorCode for AuthControllerError {
|
|
fn error_code(&self) -> Code {
|
|
match self {
|
|
Self::MissingParameter(_) => Code::MissingParameter,
|
|
Self::InvalidApiKeyActions(_) => Code::InvalidApiKeyActions,
|
|
Self::InvalidApiKeyIndexes(_) => Code::InvalidApiKeyIndexes,
|
|
Self::InvalidApiKeyExpiresAt(_) => Code::InvalidApiKeyExpiresAt,
|
|
Self::InvalidApiKeyDescription(_) => Code::InvalidApiKeyDescription,
|
|
Self::ApiKeyNotFound(_) => Code::ApiKeyNotFound,
|
|
Self::Internal(_) => Code::Internal,
|
|
}
|
|
}
|
|
}
|