2021-09-21 19:23:22 +08:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
|
2022-06-06 18:38:46 +08:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2021-09-21 19:23:22 +08:00
|
|
|
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.
|
2021-09-27 21:41:14 +08:00
|
|
|
UserError::SerdeJson(_)
|
2021-10-27 01:36:48 +08:00
|
|
|
| UserError::DocumentLimitReached
|
2022-06-16 21:58:39 +08:00
|
|
|
| UserError::AccessingSoftDeletedDocument { .. }
|
2021-10-27 01:36:48 +08:00
|
|
|
| UserError::UnknownInternalDocumentId { .. } => Code::Internal,
|
2021-11-03 21:25:49 +08:00
|
|
|
UserError::InvalidStoreFile => Code::InvalidStore,
|
|
|
|
UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice,
|
|
|
|
UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached,
|
2021-09-21 19:23:22 +08:00
|
|
|
UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded,
|
|
|
|
UserError::InvalidFilter(_) => Code::Filter,
|
|
|
|
UserError::MissingDocumentId { .. } => Code::MissingDocumentId,
|
2022-06-16 21:58:39 +08:00
|
|
|
UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => {
|
|
|
|
Code::InvalidDocumentId
|
|
|
|
}
|
2021-09-21 19:23:22 +08:00
|
|
|
UserError::MissingPrimaryKey => Code::MissingPrimaryKey,
|
2021-10-27 01:36:48 +08:00
|
|
|
UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent,
|
2021-09-21 19:23:22 +08:00
|
|
|
UserError::SortRankingRuleMissing => Code::Sort,
|
|
|
|
UserError::InvalidFacetsDistribution { .. } => Code::BadRequest,
|
2021-09-28 20:49:13 +08:00
|
|
|
UserError::InvalidSortableAttribute { .. } => Code::Sort,
|
2021-09-27 21:41:14 +08:00
|
|
|
UserError::CriterionError(_) => Code::InvalidRankingRule,
|
|
|
|
UserError::InvalidGeoField { .. } => Code::InvalidGeoField,
|
2021-09-28 20:49:13 +08:00
|
|
|
UserError::SortError(_) => Code::Sort,
|
2022-03-22 23:28:00 +08:00
|
|
|
UserError::InvalidMinTypoWordLenSetting(_, _) => {
|
|
|
|
Code::InvalidMinWordLengthForTypo
|
|
|
|
}
|
2021-09-21 19:23:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|