diff --git a/meilisearch-http/src/error.rs b/meilisearch-http/src/error.rs index 3f57e3a92..953a5457e 100644 --- a/meilisearch-http/src/error.rs +++ b/meilisearch-http/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; use actix_http::ResponseBuilder; use actix_web as aweb; -use actix_web::error::JsonPayloadError; +use actix_web::error::{JsonPayloadError, QueryPayloadError}; use actix_web::http::StatusCode; use serde_json::json; @@ -260,7 +260,15 @@ impl From for Error { } } -pub fn json_error_handler(err: JsonPayloadError) -> ResponseError { - let error = Error::from(err); +impl From for Error { + fn from(err: QueryPayloadError) -> Error { + match err { + QueryPayloadError::Deserialize(err) => Error::BadRequest(format!("Invalid query parameters: {}", err)), + } + } +} + +pub fn payload_error_handler>(err: E) -> ResponseError { + let error: Error = err.into(); error.into() } diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index 4b68c5120..486f4a39f 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -18,7 +18,7 @@ use meilisearch_core::ProcessedUpdateResult; pub use option::Opt; pub use self::data::Data; -use self::error::{json_error_handler, ResponseError}; +use self::error::{payload_error_handler, ResponseError}; pub fn create_app( data: &Data, @@ -38,7 +38,11 @@ pub fn create_app( web::JsonConfig::default() .limit(data.http_payload_size_limit) .content_type(|_mime| true) // Accept all mime types - .error_handler(|err, _req| json_error_handler(err).into()), + .error_handler(|err, _req| payload_error_handler(err).into()), + ) + .app_data( + web::QueryConfig::default() + .error_handler(|err, _req| payload_error_handler(err).into()) ) .service(routes::load_html) .service(routes::load_css)