How to intercept all exceptions in flask?
You should use errorhandler
, see documentation http://flask.pocoo.org/docs/patterns/errorpages/#error-handlers and http://flask.pocoo.org/docs/api/#flask.Flask.errorhandler. It is allow you get all exceptions raised in dispatchers, but not handle exceptions in error handlers. For example to handle all exceptions:
@app.errorhandler(Exception)def all_exception_handler(error): return 'Error', 500
How ever I prefer explicit exceptions handlers or use decorators (class based views) for this cases.
Try something like this:
@app.errorhandler(Exception)def all_exception_handler(error): return "Error: " + error.code