Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for flask 0.x and register default error handler only for HTTPException #12

Merged
merged 2 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions flask_rest_api/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Exception handler"""

from werkzeug.exceptions import (
default_exceptions, HTTPException, InternalServerError)
from werkzeug.exceptions import HTTPException, InternalServerError
from flask import jsonify, current_app


Expand All @@ -11,15 +10,10 @@ class ErrorHandlerMixin:
def _register_error_handlers(self):
"""Register error handlers in Flask app

This method registers an error handler for every exception code.
This method registers a default error handler for HTTPException.
"""
# On Flask versions older than 1.0, it is not possible to register a
# handler for all HTTPException at once, so we register the handler
# for each code explicitly.
# https://github.com/pallets/flask/issues/941#issuecomment-118975275
# This workaround can be dropped when dropping Flask<1.0 compatibility.
for code in default_exceptions:
self._app.register_error_handler(code, self.handle_http_exception)
self._app.register_error_handler(
HTTPException, self.handle_http_exception)

def handle_http_exception(self, error):
"""Return error description and details in response body
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
install_requires=[
'werkzeug>=0.11',
'flask>=0.11',
'flask>=1.0',
'marshmallow>=2.15.2',
'webargs>=1.5.2',
'apispec>=0.39.0',
Expand Down