mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 08:14:26 +01:00
Reapply #2819
This commit is contained in:
parent
2a7ef3b352
commit
fce0996e17
@ -8,6 +8,7 @@ use either::Either;
|
|||||||
use milli::documents::{DocumentsBatchBuilder, Error};
|
use milli::documents::{DocumentsBatchBuilder, Error};
|
||||||
use milli::Object;
|
use milli::Object;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_json::error::Category;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, DocumentFormatError>;
|
type Result<T> = std::result::Result<T, DocumentFormatError>;
|
||||||
|
|
||||||
@ -40,18 +41,24 @@ impl Display for DocumentFormatError {
|
|||||||
Self::Internal(e) => write!(f, "An internal error has occurred: `{}`.", e),
|
Self::Internal(e) => write!(f, "An internal error has occurred: `{}`.", e),
|
||||||
Self::MalformedPayload(me, b) => match me.borrow() {
|
Self::MalformedPayload(me, b) => match me.borrow() {
|
||||||
Error::Json(se) => {
|
Error::Json(se) => {
|
||||||
|
let mut message = match se.classify() {
|
||||||
|
Category::Data => {
|
||||||
|
"data are neither an object nor a list of objects".to_string()
|
||||||
|
}
|
||||||
|
_ => se.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
// https://github.com/meilisearch/meilisearch/issues/2107
|
// https://github.com/meilisearch/meilisearch/issues/2107
|
||||||
// The user input maybe insanely long. We need to truncate it.
|
// The user input maybe insanely long. We need to truncate it.
|
||||||
let mut serde_msg = se.to_string();
|
|
||||||
let ellipsis = "...";
|
let ellipsis = "...";
|
||||||
let trim_input_prefix_len = 50;
|
let trim_input_prefix_len = 50;
|
||||||
let trim_input_suffix_len = 85;
|
let trim_input_suffix_len = 85;
|
||||||
|
|
||||||
if serde_msg.len()
|
if message.len()
|
||||||
> trim_input_prefix_len + trim_input_suffix_len + ellipsis.len()
|
> trim_input_prefix_len + trim_input_suffix_len + ellipsis.len()
|
||||||
{
|
{
|
||||||
serde_msg.replace_range(
|
message.replace_range(
|
||||||
trim_input_prefix_len..serde_msg.len() - trim_input_suffix_len,
|
trim_input_prefix_len..message.len() - trim_input_suffix_len,
|
||||||
ellipsis,
|
ellipsis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -59,7 +66,7 @@ impl Display for DocumentFormatError {
|
|||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.",
|
"The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.",
|
||||||
b, serde_msg
|
b, message
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me),
|
_ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me),
|
||||||
|
Loading…
Reference in New Issue
Block a user