Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom handling of extractor errors #181

Closed
connec opened this issue Apr 13, 2018 · 5 comments
Closed

Support custom handling of extractor errors #181

connec opened this issue Apr 13, 2018 · 5 comments

Comments

@connec
Copy link

connec commented Apr 13, 2018

Example:

fn main() {
    ...
    App::new().resource("/items", |r| r.with(create_item))
    ...
}

#[derive(Deserialize)]
struct Item {
    ...
}

fn create_item(item: Json<Item>) -> HttpResponse {
    ...
}

Currently, if there is a deserialization error when attempting to extract an Item (e.g. because the JSON payload has missing fields, or is the wrong type) an empty HTTP 400 Bad Request response will be returned due to the impl of ResponseError for DeError.

Whilst this is sufficient for experimental or internal APIs, it would be useful to be able to customise or override how errors are handled. For myself, I wanted to include the text of the serialization error in the response body so consumers can debug their bad requests.

@fafhrd91
Copy link
Member

added JsonConfig::error_handler()

@fafhrd91
Copy link
Member

@connec
Copy link
Author

connec commented Apr 14, 2018

Wow, quick update, thanks! I will give it a try 😄

@fierydrake
Copy link

fierydrake commented Jan 2, 2020

@axic
Copy link

axic commented Oct 17, 2023

Active docs at https://docs.rs/actix-web/latest/actix_web/web/struct.JsonConfig.html#method.error_handler

@actix actix locked as resolved and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants