-1

This article for flask 1.0.x mentions we must use app_errorhandler (example:@bp.app_errorhandler)

This and this SO answers also mention that we must use app_errorhandler (example:@bp.app_errorhandler)

This article for flask 1.0.x mentions we must use errorhandler (example: @bp.errorhandler)

Why does documentation for 1.0.x mention 2 different things and which is the correct approach to register blueprint level error handler in Flask 1.0.2?

variable
  • 8,262
  • 9
  • 95
  • 215

1 Answers1

-1

There are no correct or incorrect approach for this kind of situation,

I definitely recommend you to use the Blueprint level error handler @bp.errorhandler, but for specific errors that are directly related to Models/Helpers/Services/...etc inside of your Blueprint execution.

However, I recommend you to handle errors that are common on all blueprints and their responses are pretty much the same on each blueprint, with your Flask app error handler @app.errorhandler.

This way you will remove any duplicate logic for error handling.

Radwan Abu-Odeh
  • 1,897
  • 9
  • 16
  • What situation do you refer to? The documentation for 1.0.x shows both approaches - but using the app_errorhandler doesn't work for me - does it work for you? – variable Jan 22 '20 at 12:30
  • if `app_errorhandler` doesn't do it for you, then use `bp_errorhandler`, What worked for me, is putting all common error handlers on `app_errorhandler`, and blueprint specific error handlers on the blueprint – Radwan Abu-Odeh Jan 22 '20 at 12:57