You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
Sorry to post this here - completely new to flask-restful, but ...
From the docs, I expected that flask-restful arg_parse() would return
an http page with error code (e.g., 400) + any error messages accumulated
while parsing the query string.
However, the error messages do not appear.
I can see that the error messages are accumulating correctly in
reqparse.py (e.g., handle_validation_error with bundle_errors=True).
When I look at the flask-restful.abort(), I don't understand how this is meant to work:
Inside__init__.py:
def abort(http_status_code, **kwargs):
"""Raise a HTTPException for the given http_status_code. Attach any keyword
arguments to the exception for later processing.
"""
#noinspection PyUnresolvedReferences
try:
original_flask_abort(http_status_code)
except HTTPException as e:
if len(kwargs):
e.data = kwargs
raise
To me, it looks like you return an original flask abort page with no message, and then raise the flask-restful error message as an exception. How is this meant to work ?
e.g., if I just try to do:
import flask_restful
flask_restful.abort(400, message={'field1': 'this is required', 'field2': 'got a bad value'})
My understanding from the docs is that this should be all that is required to return html with error messages, but it does not.
Thanks!!
The text was updated successfully, but these errors were encountered:
The abort function in Flask-RESTful is meant to provide an enhanced version of Flask's abort function by allowing you to attach custom error messages or any other keyword arguments to the raised HTTPException.
Here's how it works:
When you call abort(http_status_code, **kwargs), it first tries to invoke Flask's built-in abort function with the provided http_status_code.
Flask's abort raises an HTTPException for the given status code.
The except HTTPException as e block catches this raised exception.
If any keyword arguments were passed (like custom error messages), they are attached to the data attribute of the caught exception.
The exception (now with the attached data) is raised again, and Flask-RESTful catches it and processes it to return a response with the custom error messages.
The problem you're facing might be because of how your application is set up. Here are some things to check:
Check for other error handlers: If you have other error handlers in your Flask application (using @app.errorhandler), they might interfere with Flask-RESTful's error handling mechanism. Ensure these handlers return the error messages you expect.
Ensure bundle_errors is set: If you're using Flask-RESTful's reqparse to parse request data and want to bundle all error messages together, ensure you've set bundle_errors=True in your Api instance:
Hi.
Sorry to post this here - completely new to flask-restful, but ...
From the docs, I expected that flask-restful arg_parse() would return
an http page with error code (e.g., 400) + any error messages accumulated
while parsing the query string.
However, the error messages do not appear.
I can see that the error messages are accumulating correctly in
reqparse.py (e.g., handle_validation_error with bundle_errors=True).
When I look at the flask-restful.abort(), I don't understand how this is meant to work:
Inside__init__.py:
To me, it looks like you return an original flask abort page with no message, and then raise the flask-restful error message as an exception. How is this meant to work ?
e.g., if I just try to do:
import flask_restful
flask_restful.abort(400, message={'field1': 'this is required', 'field2': 'got a bad value'})
My understanding from the docs is that this should be all that is required to return html with error messages, but it does not.
Thanks!!
The text was updated successfully, but these errors were encountered: