https://github.com/devxoul/flask-errorhandler
Error handlers for Flask blueprints.
https://github.com/devxoul/flask-errorhandler
Last synced: 3 months ago
JSON representation
Error handlers for Flask blueprints.
- Host: GitHub
- URL: https://github.com/devxoul/flask-errorhandler
- Owner: devxoul
- License: bsd-3-clause
- Created: 2014-05-14T09:16:53.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T12:24:08.000Z (about 5 years ago)
- Last Synced: 2025-02-03T17:55:45.757Z (5 months ago)
- Language: Python
- Homepage:
- Size: 129 KB
- Stars: 7
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
Flask-ErrorHandler
==================Flask-ErrorHandler provides a generic error handler for blueprints.
Sample:
.. code-block:: python
from flask import Flask, Blueprint
from flask.ext.errorhandler import ErrorHandler
import jsonapp = Flask(__name__)
api_blueprint = Blueprint('api', 'api')
web_blueprint = Blueprint('web', 'web')errorhandler = ErrorHandler()
errorhandler.init_app(app)@errorhandler.errorhandler(api_blueprint)
def handle_error(e):
data = {
'error': {
'code': e.code,
'message': e.description
}
}
response = Response(json.dumps(data),
mimetype='application/json',
status=e.code)
return response@errorhandler.errorhandler(web_blueprint)
def handle_error(e):
body = '%d
%s
' % (e.code, e.description)
response = Response(body, mimetype='text/html', status=e.code)
return response