Generic error handlers for Flask blueprints.
Project description
Flask-ErrorHandler provides a generic error handler for blueprints.
Sample:
from flask import Flask, Blueprint
from flask.ext.errorhandler import ErrorHandler
import json
app = 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 = '<h1>%d</h1><p>%s</p>' % (e.code, e.description)
response = Response(body, mimetype='text/html', status=e.code)
return response
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-ErrorHandler-0.1.0.tar.gz.
File metadata
- Download URL: Flask-ErrorHandler-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b752a4464661c2edb940b42b1355003cdff8c0b2975fe5254c25a8239fd9f6
|
|
| MD5 |
f463b6ed8a7839163dcde2d225c549c3
|
|
| BLAKE2b-256 |
74b8f29522645605908c9ef28b8371c2a71a23a573f9b24bcb83ec44f213d71f
|