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

Documentation example for Flask error handling crashes #168

Closed
nebularazer opened this issue May 18, 2017 · 0 comments

Comments

@nebularazer
Copy link
Contributor

commented May 18, 2017

The docs example for the flask error handler crashes due to changes in b8f7e00

from flask import Flask, jsonify
from marshmallow import fields
from webargs.flaskparser import use_args

app = Flask(__name__)


@app.errorhandler(422)
def handle_unprocessable_entity(err):
    # webargs attaches additional metadata to the `data` attribute
    data = getattr(err, 'data')
    if data:
        # Get validations from the ValidationError object
        messages = data['exc'].messages
    else:
        messages = ['Invalid request']
    return jsonify({
        'messages': messages,
    }), 422


@app.route('/', methods=['POST'])
@use_args({'notaint': fields.Str()})
def error(args):
    return args.get('notaint')

if __name__ == '__main__':
    app.run()
# sending a Int
curl -H "Content-Type: application/json" -X POST -d "{\"notaint\": 10}" http://localhost:5000/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.