46 lines
1.4 KiB
Rust
Raw Normal View History

2021-09-22 10:49:59 +02:00
use std::error::Error;
use meilisearch_error::Code;
use meilisearch_error::ErrorCode;
2021-06-21 18:42:47 +02:00
use crate::index::error::IndexError;
use super::dump_actor::error::DumpActorError;
2021-09-22 15:07:04 +02:00
use super::indexes::error::IndexActorError;
2021-09-22 11:52:29 +02:00
use super::updates::error::UpdateActorError;
2021-06-15 17:55:27 +02:00
use super::uuid_resolver::error::UuidResolverError;
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")]
MissingUid,
2021-06-24 10:53:51 +02:00
#[error("{0}")]
Uuid(#[from] UuidResolverError),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
IndexActor(#[from] IndexActorError),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
UpdateActor(#[from] UpdateActorError),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
DumpActor(#[from] DumpActorError),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
2021-06-21 18:42:47 +02:00
IndexError(#[from] IndexError),
2021-09-22 10:49:59 +02:00
#[error("Internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>),
}
impl ErrorCode for IndexControllerError {
fn error_code(&self) -> Code {
match self {
2021-06-24 10:53:51 +02:00
IndexControllerError::MissingUid => Code::BadRequest,
IndexControllerError::Uuid(e) => e.error_code(),
IndexControllerError::IndexActor(e) => e.error_code(),
IndexControllerError::UpdateActor(e) => e.error_code(),
IndexControllerError::DumpActor(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,
}
}
}