mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-06-17 01:59:49 +02:00
ffefd0caf2
implements: https://github.com/meilisearch/specifications/blob/develop/text/0085-api-keys.md - Add tests on API keys management route (meilisearch-http/tests/auth/api_keys.rs) - Add tests checking authorizations on each meilisearch routes (meilisearch-http/tests/auth/authorization.rs) - Implement API keys management routes (meilisearch-http/src/routes/api_key.rs) - Create module to manage API keys and authorizations (meilisearch-auth) - Reimplement GuardedData to extend authorizations (meilisearch-http/src/extractors/authentication/mod.rs) - Change X-MEILI-API-KEY by Authorization Bearer (meilisearch-http/src/extractors/authentication/mod.rs) - Change meilisearch routes to fit to the new authorization feature (meilisearch-http/src/routes/) - close #1867
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use std::error::Error;
|
|
|
|
use meilisearch_error::{internal_error, Code, ErrorCode};
|
|
use serde_json::Value;
|
|
|
|
use crate::error::MilliError;
|
|
|
|
pub type Result<T> = std::result::Result<T, IndexError>;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum IndexError {
|
|
#[error("An internal error has occurred. `{0}`.")]
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
|
#[error("Document `{0}` not found.")]
|
|
DocumentNotFound(String),
|
|
#[error("{0}")]
|
|
Facet(#[from] FacetError),
|
|
#[error("{0}")]
|
|
Milli(#[from] milli::Error),
|
|
}
|
|
|
|
internal_error!(
|
|
IndexError: std::io::Error,
|
|
heed::Error,
|
|
fst::Error,
|
|
serde_json::Error
|
|
);
|
|
|
|
impl ErrorCode for IndexError {
|
|
fn error_code(&self) -> Code {
|
|
match self {
|
|
IndexError::Internal(_) => Code::Internal,
|
|
IndexError::DocumentNotFound(_) => Code::DocumentNotFound,
|
|
IndexError::Facet(e) => e.error_code(),
|
|
IndexError::Milli(e) => MilliError(e).error_code(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum FacetError {
|
|
#[error("Invalid syntax for the filter parameter: `expected {}, found: {1}`.", .0.join(", "))]
|
|
InvalidExpression(&'static [&'static str], Value),
|
|
}
|
|
|
|
impl ErrorCode for FacetError {
|
|
fn error_code(&self) -> Code {
|
|
match self {
|
|
FacetError::InvalidExpression(_, _) => Code::Filter,
|
|
}
|
|
}
|
|
}
|