Skip to content

Instantly share code, notes, and snippets.

@danielknell
Created May 31, 2017 07:53
Show Gist options
  • Save danielknell/2e1021656f92e77bd748a1013d6942c1 to your computer and use it in GitHub Desktop.
Save danielknell/2e1021656f92e77bd748a1013d6942c1 to your computer and use it in GitHub Desktop.
from flask import Flask, Response
from werkzeug.exceptions import HTTPException, NotFound
app = Flask('test')
def handler(e):
return Response('error')
app.register_error_handler(HTTPException, handler)
@app.route('/')
def index():
raise NotFound()
def test_errorhandler():
client = app.test_client()
response = client.get('/')
assert response.data == "error"
@danielknell
Copy link
Author

danielknell commented May 31, 2017

Based on how _find_error_handler recurses through the mro, i would expect this to pass, as the second item in NotFound's mro is HTTPException.

Instead this fails showing the default response for the NotFound exception.

_find_error_handler is used to fetch the handler for a http exception, at line 1468 it appears to be None though.

Flask==0.12.2
Werkzeug==0.12.2
Python==3.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment