From 7ddab7ef3182399023cee1dd388cb3287338eaf0 Mon Sep 17 00:00:00 2001 From: Marin Postma Date: Wed, 15 Dec 2021 10:30:00 +0100 Subject: [PATCH] bug(lib): fix get dumps bad error code --- meilisearch-http/tests/common/server.rs | 5 +++++ meilisearch-http/tests/dumps.rs | 22 +++++++++++++++++++ meilisearch-lib/src/index_controller/error.rs | 5 +---- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 meilisearch-http/tests/dumps.rs diff --git a/meilisearch-http/tests/common/server.rs b/meilisearch-http/tests/common/server.rs index 7116833f5..115b4650c 100644 --- a/meilisearch-http/tests/common/server.rs +++ b/meilisearch-http/tests/common/server.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use std::path::Path; use actix_web::http::StatusCode; @@ -88,6 +89,10 @@ impl Server { pub async fn tasks(&self) -> (Value, StatusCode) { self.service.get("/tasks").await } + + pub async fn get_dump_status(&self, uid: &str) -> (Value, StatusCode) { + self.service.get(format!("/dumps/{}/status", uid)).await + } } pub fn default_settings(dir: impl AsRef) -> Opt { diff --git a/meilisearch-http/tests/dumps.rs b/meilisearch-http/tests/dumps.rs new file mode 100644 index 000000000..843347bde --- /dev/null +++ b/meilisearch-http/tests/dumps.rs @@ -0,0 +1,22 @@ +#![allow(dead_code)] +mod common; + +use crate::common::Server; +use serde_json::json; + +#[actix_rt::test] +async fn get_unexisting_dump_status() { + let server = Server::new().await; + + let (response, code) = server.get_dump_status("foobar").await; + assert_eq!(code, 404); + + let expected_response = json!({ + "message": "Dump `foobar` not found.", + "code": "dump_not_found", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#dump_not_found" + }); + + assert_eq!(response, expected_response); +} diff --git a/meilisearch-lib/src/index_controller/error.rs b/meilisearch-lib/src/index_controller/error.rs index 6ec1cea35..85af76623 100644 --- a/meilisearch-lib/src/index_controller/error.rs +++ b/meilisearch-lib/src/index_controller/error.rs @@ -59,10 +59,7 @@ impl ErrorCode for IndexControllerError { IndexControllerError::DocumentFormatError(e) => e.error_code(), IndexControllerError::MissingPayload(_) => Code::MissingPayload, IndexControllerError::PayloadTooLarge => Code::PayloadTooLarge, - IndexControllerError::DumpError(DumpActorError::DumpAlreadyRunning) => { - Code::DumpAlreadyInProgress - } - IndexControllerError::DumpError(_) => Code::DumpProcessFailed, + IndexControllerError::DumpError(e) => e.error_code(), } } }