mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-28 15:31:38 +01: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
49 lines
2.1 KiB
Rust
49 lines
2.1 KiB
Rust
use std::error::Error;
|
|
use std::fmt;
|
|
|
|
use meilisearch_error::{Code, ErrorCode};
|
|
use milli::UserError;
|
|
|
|
#[derive(Debug)]
|
|
pub struct MilliError<'a>(pub &'a milli::Error);
|
|
|
|
impl Error for MilliError<'_> {}
|
|
|
|
impl fmt::Display for MilliError<'_> {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
self.0.fmt(f)
|
|
}
|
|
}
|
|
|
|
impl ErrorCode for MilliError<'_> {
|
|
fn error_code(&self) -> Code {
|
|
match self.0 {
|
|
milli::Error::InternalError(_) => Code::Internal,
|
|
milli::Error::IoError(_) => Code::Internal,
|
|
milli::Error::UserError(ref error) => {
|
|
match error {
|
|
// TODO: wait for spec for new error codes.
|
|
UserError::SerdeJson(_)
|
|
| UserError::DocumentLimitReached
|
|
| UserError::UnknownInternalDocumentId { .. } => Code::Internal,
|
|
UserError::InvalidStoreFile => Code::InvalidStore,
|
|
UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice,
|
|
UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached,
|
|
UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded,
|
|
UserError::InvalidFilter(_) => Code::Filter,
|
|
UserError::MissingDocumentId { .. } => Code::MissingDocumentId,
|
|
UserError::InvalidDocumentId { .. } => Code::InvalidDocumentId,
|
|
UserError::MissingPrimaryKey => Code::MissingPrimaryKey,
|
|
UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent,
|
|
UserError::SortRankingRuleMissing => Code::Sort,
|
|
UserError::InvalidFacetsDistribution { .. } => Code::BadRequest,
|
|
UserError::InvalidSortableAttribute { .. } => Code::Sort,
|
|
UserError::CriterionError(_) => Code::InvalidRankingRule,
|
|
UserError::InvalidGeoField { .. } => Code::InvalidGeoField,
|
|
UserError::SortError(_) => Code::Sort,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|