mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
Change malformed_payload error
This commit is contained in:
parent
8ec0c4c913
commit
61c15b69fb
@ -39,9 +39,9 @@ impl fmt::Display for ErrorType {
|
||||
use ErrorType::*;
|
||||
|
||||
match self {
|
||||
InternalError => write!(f, "internal_error"),
|
||||
InvalidRequestError => write!(f, "invalid_request_error"),
|
||||
AuthenticationError => write!(f, "authentication_error"),
|
||||
InternalError => write!(f, "internal"),
|
||||
InvalidRequestError => write!(f, "invalid_request"),
|
||||
AuthenticationError => write!(f, "authentication"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,11 @@ pub struct ResponseError {
|
||||
#[serde(skip)]
|
||||
code: StatusCode,
|
||||
message: String,
|
||||
#[serde(rename = "code")]
|
||||
error_code: String,
|
||||
#[serde(rename = "type")]
|
||||
error_type: String,
|
||||
#[serde(rename = "link")]
|
||||
error_link: String,
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ async fn error_add_malformed_csv_documents() {
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "text/csv"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -203,20 +203,22 @@ async fn error_add_malformed_csv_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The csv payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The csv payload provided is malformed. CSV error: record 1 (line: 2, byte: 12): found record with 3 fields, but the previous record has 2 fields."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
|
||||
// put
|
||||
let req = test::TestRequest::put()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "text/csv"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -225,13 +227,15 @@ async fn error_add_malformed_csv_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The csv payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The csv payload provided is malformed. CSV error: record 1 (line: 2, byte: 12): found record with 3 fields, but the previous record has 2 fields."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
}
|
||||
|
||||
@ -250,7 +254,7 @@ async fn error_add_malformed_json_documents() {
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "application/json"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -259,20 +263,22 @@ async fn error_add_malformed_json_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The json payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The json payload provided is malformed. key must be a string at line 1 column 14."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
|
||||
// put
|
||||
let req = test::TestRequest::put()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "application/json"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -281,13 +287,15 @@ async fn error_add_malformed_json_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The json payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The json payload provided is malformed. key must be a string at line 1 column 14."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
}
|
||||
|
||||
@ -306,7 +314,7 @@ async fn error_add_malformed_ndjson_documents() {
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "application/x-ndjson"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -315,20 +323,22 @@ async fn error_add_malformed_ndjson_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The ndjson payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The ndjson payload provided is malformed. key must be a string at line 2 column 2."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
|
||||
// put
|
||||
let req = test::TestRequest::put()
|
||||
.uri("/indexes/dog/documents")
|
||||
.set_payload(document.to_string())
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-type", "application/x-ndjson"))
|
||||
.to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
@ -337,13 +347,15 @@ async fn error_add_malformed_ndjson_documents() {
|
||||
assert_eq!(status_code, 400);
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"The ndjson payload provided is malformed. :syntaxErrorHelper."#)
|
||||
json!(
|
||||
r#"The ndjson payload provided is malformed. key must be a string at line 2 column 2."#
|
||||
)
|
||||
);
|
||||
assert_eq!(response["code"], "malformed_payload");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(response["code"], json!("malformed_payload"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#malformed_payload"
|
||||
json!("https://docs.meilisearch.com/errors#malformed_payload")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl fmt::Display for PayloadType {
|
||||
pub enum DocumentFormatError {
|
||||
#[error("Internal error: {0}")]
|
||||
Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
#[error("{0}. The {1} payload provided is malformed.")]
|
||||
#[error("The {1} payload provided is malformed. {0}.")]
|
||||
MalformedPayload(
|
||||
Box<dyn std::error::Error + Send + Sync + 'static>,
|
||||
PayloadType,
|
||||
|
Loading…
Reference in New Issue
Block a user