Open sanzoghenzo opened 5 years ago
Its not even hitting the custom error handler for me and always hitting the generic_error_handler. Any suggestions on that?
Seems like this would be a pretty straight forward fix. The webargs function accepts several parameters I feel flask-apispec could support. I'll try and work on a PR for this if it seems worth-while/possible.
Using the code in the original post the error code seems to be adjustable but the error messages don't get passed to the end reponse.
This is the code I am referring too
@parser.error_handler
def handle_request_parsing_error(err, req, schema, error_status_code, error_headers):
"""webargs error handler that uses Flask-RESTful's abort function to return
a JSON error response to the client.
"""
status_code = error_status_code or 400 # if set to 422 the error code will be 422
abort(status_code, errors=err.messages)
This is what I ended up using https://gist.github.com/hirobert/394981a661cbf78d442e
Wrapper's call to parser.parse doesn't set
error_status_code
, so custom error_handlers getsNone
as status code on ValidationError.I had to manually add a 400 status code in my error handler. Here's the relevant code: