add assert message for errorhandler exception type

This commit is contained in:
jackwardell 2020-04-16 17:01:51 +01:00 committed by David Lord
parent 2062d984ab
commit 846ee2c62e
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 11 additions and 1 deletions

View file

@ -1270,7 +1270,9 @@ class Flask(_PackageBoundObject):
else:
exc_class = exc_class_or_code
assert issubclass(exc_class, Exception)
assert issubclass(
exc_class, Exception
), "Custom exceptions must be subclasses of Exception."
if issubclass(exc_class, HTTPException):
return exc_class, exc_class.code

View file

@ -11,11 +11,19 @@ def test_error_handler_no_match(app, client):
class CustomException(Exception):
pass
class UnacceptableCustomException(BaseException):
pass
@app.errorhandler(CustomException)
def custom_exception_handler(e):
assert isinstance(e, CustomException)
return "custom"
with pytest.raises(
AssertionError, match="Custom exceptions must be subclasses of Exception."
):
app.register_error_handler(UnacceptableCustomException, None)
@app.errorhandler(500)
def handle_500(e):
assert isinstance(e, InternalServerError)