diff --git a/meilisearch/src/error.rs b/meilisearch/src/error.rs index bec233971..23a101080 100644 --- a/meilisearch/src/error.rs +++ b/meilisearch/src/error.rs @@ -55,7 +55,7 @@ impl ErrorCode for MeilisearchHttpError { MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload, MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType, MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound, - MeilisearchHttpError::InvalidExpression(_, _) => Code::Filter, + MeilisearchHttpError::InvalidExpression(_, _) => Code::InvalidSearchFilter, MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge, MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes, MeilisearchHttpError::IndexUid(e) => e.error_code(), diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index cd6dc6e30..39af9bedb 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -695,7 +695,7 @@ fn parse_filter(facets: &Value) -> Result, MeilisearchHttpError> Ok(condition) } Value::Array(arr) => parse_filter_array(arr), - v => Err(MeilisearchHttpError::InvalidExpression(&["Array"], v.clone())), + v => Err(MeilisearchHttpError::InvalidExpression(&["String", "Array"], v.clone())), } } diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 1a82dcbc5..60a52d07d 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -233,20 +233,26 @@ async fn search_bad_attributes_to_highlight() { #[actix_rt::test] async fn search_bad_filter() { + // Since a filter is deserialized as a json Value it will never fail to deserialize. + // Thus the error message is not generated by deserr but written by us. let server = Server::new().await; let index = server.index("test"); + // Also, to trigger the error message we need to effectively create the index or else it'll throw an + // index does not exists error. + let (_, code) = index.create(None).await; + snapshot!(code, @"202 Accepted"); - // Can't make the `filter` fail with a get search since it'll accept anything as a strings. let (response, code) = index.search_post(json!({ "filter": true })).await; - snapshot!(code, @"404 Not Found"); + snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { - "message": "Index `test` not found.", - "code": "index_not_found", + "message": "Invalid syntax for the filter parameter: `expected String, Array, found: true`.", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#index-not-found" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" } "###); + // Can't make the `filter` fail with a get search since it'll accept anything as a strings. } #[actix_rt::test]