0
votes

I use Flask and more precisely abort with an error handler. I can custom the message sent with my error by using make_response. I also use Blueprints to register the error handler.

Before today, everything were fine. But things go bad today and it is impossible to custom my message anymore.

For my example, I take the 401 error and I try to send the message "custom message"

My handler for error 401

@errors.app_errorhandler(401)
def access_denied(error):
    # if the description have the message attribute
    if 'message' in error.description:
        return make_response(jsonify(
            {
                'error': error.description['message']
            }
        ), 401)
    else:
        return make_response(jsonify(
            {
                'error': 'Access Denied'
            }
        ), 401)

My blueprint registration in __init__.py

from app.errors.ErrorHandler import errors
app.register_blueprint(errors)

My abort call

from flask import abort
abort(
      401,
      {
           'message': 'custom message'
      }
)

The error 401 is handled by my handler but the message sent is the default message 'Access Denied'.

I insist : Everything worked yesterday ! (19 March 2019 - 6pm) Maybe it is a bug or an improvement not documented at all

Thank you for your help and if you need more information, feel free to ask

Louis

1

1 Answers

0
votes

The problem was from the werkzeug module : https://github.com/pallets/werkzeug/issues/1483

It is fixed now