Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-ErrorHandler, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size Flask-ErrorHandler-0.1.0.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page