Last active
December 12, 2015 09:09
-
-
Save tehasdf/4749354 to your computer and use it in GitHub Desktop.
throwing errors from within errorhandlers with flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, abort | |
app = Flask(__name__) | |
@app.route('/') | |
def foo(): | |
abort(403) | |
return 'this wont ever be returned' | |
@app.errorhandler(403) | |
def foo(x): | |
# here we throw an exception inside an error handler | |
abort(404) | |
return 'this wont ever be returned' | |
@app.errorhandler(404) | |
def foo(x): | |
return 'im the 404 handler' | |
@app.errorhandler(500) | |
def foo(err): | |
# check here for a 500 to avoid an infinite loop | |
return app.handle_user_exception(err) | |
with app.test_client() as c: | |
assert c.get('/').data == 'im the 404 handler' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment