Catching multiple exceptions / status codes with @app.errorhandler

Viewed 76

If I want to catch an exception and a status code with @app.errorhandler, what's the best way to do this? I notice you can put the decorator twice like this:

class BadRequestError(Exception):
    pass

@app.errorhandler(400)
@app.errorhandler(BadRequestError)
def serve_400_error(error: Exception) -> Response:
    return client_error_page(400)

But it acts a bit funky making me wonder if this is best practice. For example, swapping the 2 decorators results in a Mypy error, as does changing the var name error to _.

0 Answers
Related