Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

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

This version
History Node

0.1.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask-ErrorHandler-0.1.0.tar.gz (3.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page