mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
first try
This commit is contained in:
parent
0c9e8cdf8d
commit
58e2903177
@ -1,4 +1,5 @@
|
|||||||
use std::fmt;
|
use std::borrow::Borrow;
|
||||||
|
use std::fmt::{self, Debug, Display};
|
||||||
use std::io::{self, BufRead, BufReader, BufWriter, Cursor, Read, Seek, Write};
|
use std::io::{self, BufRead, BufReader, BufWriter, Cursor, Read, Seek, Write};
|
||||||
|
|
||||||
use meilisearch_error::{internal_error, Code, ErrorCode};
|
use meilisearch_error::{internal_error, Code, ErrorCode};
|
||||||
@ -23,16 +24,27 @@ impl fmt::Display for PayloadType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DocumentFormatError {
|
pub enum DocumentFormatError {
|
||||||
#[error("An internal error has occurred. `{0}`.")]
|
|
||||||
Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
|
Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||||
#[error("The `{1}` payload provided is malformed. `{0}`.")]
|
MalformedPayload(Box<milli::documents::Error>, PayloadType),
|
||||||
MalformedPayload(
|
|
||||||
Box<dyn std::error::Error + Send + Sync + 'static>,
|
|
||||||
PayloadType,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
impl Display for DocumentFormatError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Internal(e) => write!(f, "An internal error has occurred. `{}`.", e),
|
||||||
|
Self::MalformedPayload(me, b) => match me.borrow() {
|
||||||
|
milli::documents::Error::JsonError(_) => write!(
|
||||||
|
f,
|
||||||
|
"The `{}` payload provided is malformed. line: {}",
|
||||||
|
b, "TODO"
|
||||||
|
),
|
||||||
|
_ => write!(f, "The `{}` payload provided is malformed. line: {}", b, me),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for DocumentFormatError {}
|
||||||
|
|
||||||
impl From<(PayloadType, milli::documents::Error)> for DocumentFormatError {
|
impl From<(PayloadType, milli::documents::Error)> for DocumentFormatError {
|
||||||
fn from((ty, error): (PayloadType, milli::documents::Error)) -> Self {
|
fn from((ty, error): (PayloadType, milli::documents::Error)) -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user