Update error message and add tests for incomplete compressed document

This commit is contained in:
karribalu 2024-06-25 18:36:29 +01:00
parent 2a38f5c757
commit 2608a596a0
2 changed files with 53 additions and 1 deletions

View File

@ -111,7 +111,7 @@ impl From<aweb::error::PayloadError> for MeilisearchHttpError {
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum ActixPayloadError { pub enum ActixPayloadError {
#[error("The provided payload is incomplete and cannot be decompressed")] #[error("The provided payload is incomplete and cannot be parsed")]
IncompleteError, IncompleteError,
#[error(transparent)] #[error(transparent)]
OtherError(aweb::error::PayloadError), OtherError(aweb::error::PayloadError),

View File

@ -183,6 +183,58 @@ async fn add_single_document_gzip_encoded() {
} }
"###); "###);
} }
#[actix_rt::test]
async fn add_single_document_gzip_encoded_with_incomplete_error() {
let document = json!("kefir");
// this is a what is expected and should work
let server = Server::new().await;
let app = server.init_web_app().await;
// post
let document = serde_json::to_string(&document).unwrap();
let req = test::TestRequest::post()
.uri("/indexes/dog/documents")
.set_payload(document.to_string())
.insert_header(("content-type", "application/json"))
.insert_header(("content-encoding", "gzip"))
.to_request();
let res = test::call_service(&app, req).await;
let status_code = res.status();
let body = test::read_body(res).await;
let response: Value = serde_json::from_slice(&body).unwrap_or_default();
snapshot!(status_code, @"400 Bad Request");
snapshot!(json_string!(response),
@r###"
{
"message": "The provided payload is incomplete and cannot be parsed",
"code": "bad_request",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#bad_request"
}
"###);
// put
let req = test::TestRequest::put()
.uri("/indexes/dog/documents")
.set_payload(document.to_string())
.insert_header(("content-type", "application/json"))
.insert_header(("content-encoding", "gzip"))
.to_request();
let res = test::call_service(&app, req).await;
let status_code = res.status();
let body = test::read_body(res).await;
let response: Value = serde_json::from_slice(&body).unwrap_or_default();
snapshot!(status_code, @"400 Bad Request");
snapshot!(json_string!(response),
@r###"
{
"message": "The provided payload is incomplete and cannot be parsed",
"code": "bad_request",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#bad_request"
}
"###);
}
/// Here we try document request with every encoding /// Here we try document request with every encoding
#[actix_rt::test] #[actix_rt::test]