MeiliSearch/meilisearch-http/src/index_controller/update_actor/error.rs

62 lines
1.9 KiB
Rust
Raw Normal View History

use std::error::Error;
use meilisearch_error::{Code, ErrorCode};
use crate::index_controller::index_actor::error::IndexActorError;
pub type Result<T> = std::result::Result<T, UpdateActorError>;
#[derive(Debug, thiserror::Error)]
2021-06-17 14:38:52 +02:00
#[allow(clippy::large_enum_variant)]
pub enum UpdateActorError {
2021-06-24 10:53:51 +02:00
#[error("Update {0} not found.")]
UnexistingUpdate(u64),
2021-06-24 10:53:51 +02:00
#[error("Internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
IndexActor(#[from] IndexActorError),
#[error(
2021-06-21 13:57:32 +02:00
"update store was shut down due to a fatal error, please check your logs for more info."
)]
FatalUpdateStoreError,
2021-06-24 10:53:51 +02:00
#[error("{0}")]
InvalidPayload(Box<dyn Error + Send + Sync + 'static>),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
PayloadError(#[from] actix_web::error::PayloadError),
}
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for UpdateActorError {
fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
Self::FatalUpdateStoreError
}
}
impl From<tokio::sync::oneshot::error::RecvError> for UpdateActorError {
fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
Self::FatalUpdateStoreError
}
}
internal_error!(
2021-06-17 14:38:52 +02:00
UpdateActorError: heed::Error,
std::io::Error,
serde_json::Error,
tokio::task::JoinError
);
impl ErrorCode for UpdateActorError {
fn error_code(&self) -> Code {
match self {
UpdateActorError::UnexistingUpdate(_) => Code::NotFound,
UpdateActorError::Internal(_) => Code::Internal,
UpdateActorError::IndexActor(e) => e.error_code(),
UpdateActorError::FatalUpdateStoreError => Code::Internal,
UpdateActorError::InvalidPayload(_) => Code::BadRequest,
2021-06-23 14:48:33 +02:00
UpdateActorError::PayloadError(error) => match error {
2021-09-08 12:34:56 +02:00
actix_web::error::PayloadError::Overflow => Code::PayloadTooLarge,
2021-06-23 14:48:33 +02:00
_ => Code::Internal,
},
}
}
}