2021-09-22 10:49:59 +02:00
|
|
|
use std::error::Error;
|
|
|
|
|
2022-06-06 12:38:46 +02:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
|
|
|
use meilisearch_types::index_uid::IndexUidFormatError;
|
|
|
|
use meilisearch_types::internal_error;
|
2021-09-24 11:53:11 +02:00
|
|
|
use tokio::task::JoinError;
|
2021-06-14 21:26:35 +02:00
|
|
|
|
2021-12-02 16:03:26 +01:00
|
|
|
use super::DocumentAdditionFormat;
|
|
|
|
use crate::document_formats::DocumentFormatError;
|
2022-05-19 14:44:24 +02:00
|
|
|
use crate::dump::error::DumpError;
|
2021-06-21 18:42:47 +02:00
|
|
|
use crate::index::error::IndexError;
|
2021-12-02 16:03:26 +01:00
|
|
|
use crate::tasks::error::TaskError;
|
|
|
|
use crate::update_file_store::UpdateFileStoreError;
|
2021-06-21 18:42:47 +02:00
|
|
|
|
2021-12-02 16:03:26 +01:00
|
|
|
use crate::index_resolver::error::IndexResolverError;
|
2021-06-14 21:26:35 +02:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, IndexControllerError>;
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum IndexControllerError {
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("Index creation must have an uid")]
|
2021-06-14 21:26:35 +02:00
|
|
|
MissingUid,
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("{0}")]
|
2021-09-24 11:53:11 +02:00
|
|
|
IndexResolver(#[from] IndexResolverError),
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("{0}")]
|
2021-06-21 18:42:47 +02:00
|
|
|
IndexError(#[from] IndexError),
|
2021-11-03 14:25:49 +01:00
|
|
|
#[error("An internal error has occurred. `{0}`.")]
|
2021-09-22 10:49:59 +02:00
|
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
2021-12-02 16:03:26 +01:00
|
|
|
#[error("{0}")]
|
|
|
|
TaskError(#[from] TaskError),
|
|
|
|
#[error("{0}")]
|
2022-05-19 14:44:24 +02:00
|
|
|
DumpError(#[from] DumpError),
|
2021-12-02 16:03:26 +01:00
|
|
|
#[error("{0}")]
|
|
|
|
DocumentFormatError(#[from] DocumentFormatError),
|
|
|
|
#[error("A {0} payload is missing.")]
|
|
|
|
MissingPayload(DocumentAdditionFormat),
|
|
|
|
#[error("The provided payload reached the size limit.")]
|
|
|
|
PayloadTooLarge,
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 16:03:26 +01:00
|
|
|
internal_error!(IndexControllerError: JoinError, UpdateFileStoreError);
|
|
|
|
|
|
|
|
impl From<actix_web::error::PayloadError> for IndexControllerError {
|
|
|
|
fn from(other: actix_web::error::PayloadError) -> Self {
|
|
|
|
match other {
|
|
|
|
actix_web::error::PayloadError::Overflow => Self::PayloadTooLarge,
|
|
|
|
_ => Self::Internal(Box::new(other)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 11:53:11 +02:00
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
impl ErrorCode for IndexControllerError {
|
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
2021-06-24 10:53:51 +02:00
|
|
|
IndexControllerError::MissingUid => Code::BadRequest,
|
2021-09-24 11:53:11 +02:00
|
|
|
IndexControllerError::IndexResolver(e) => e.error_code(),
|
2021-06-21 18:42:47 +02:00
|
|
|
IndexControllerError::IndexError(e) => e.error_code(),
|
2021-09-22 10:49:59 +02:00
|
|
|
IndexControllerError::Internal(_) => Code::Internal,
|
2021-12-02 16:03:26 +01:00
|
|
|
IndexControllerError::TaskError(e) => e.error_code(),
|
|
|
|
IndexControllerError::DocumentFormatError(e) => e.error_code(),
|
|
|
|
IndexControllerError::MissingPayload(_) => Code::MissingPayload,
|
|
|
|
IndexControllerError::PayloadTooLarge => Code::PayloadTooLarge,
|
2021-12-15 10:30:00 +01:00
|
|
|
IndexControllerError::DumpError(e) => e.error_code(),
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 12:38:46 +02:00
|
|
|
|
|
|
|
impl From<IndexUidFormatError> for IndexControllerError {
|
|
|
|
fn from(err: IndexUidFormatError) -> Self {
|
|
|
|
IndexResolverError::from(err).into()
|
|
|
|
}
|
|
|
|
}
|