Skip to main content

Default errors handler for flask application and blueprints

Project description

Set default errors handler for flask app and blueprints.

You can register handler for api that returns JSON or you can register handler for web that returns html pageor JSON if request is XHR.

Quickstart

Install flask_errors_handler using pip:

$ pip install Flask-ErrorsHandler

Example usage

from flask import Flask
from flask import abort
from flask import Blueprint

from flask_errors_handler import ErrorHandler


app = Flask(__name__)
app.config['JSON_ADD_STATUS'] = False
app.config['ERROR_PAGE'] = 'error.html'

error = ErrorHandler()
error.init_app(app)
error.api_register(app)

web = Blueprint('web', __name__)
error.web_register(web)


@app.route('/api')
def index():
    abort(500, 'Error from app')


@web.route('/web')
def index():
    abort(500, 'Error from web blueprint')


app.register_blueprint(web)
app.run()

Go to http://127.0.0.1:5000/api and see error message response as a JSON Go to http://127.0.0.1:5000/web and see error message response as an HTML page

Configuration

  1. ERROR_PAGE: (default: None) path of html template to use for show error message

  2. ERROR_DEFAULT_MSG: (default: Unhandled Exception) default message for unhandled exceptions

License MIT

Project details


Download files

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

Source Distribution

Flask-ErrorsHandler-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

Flask_ErrorsHandler-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file Flask-ErrorsHandler-1.0.0.tar.gz.

File metadata

  • Download URL: Flask-ErrorsHandler-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.6.5

File hashes

Hashes for Flask-ErrorsHandler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3eff9c30243057536aa86bb194d6a5288f80e06d5d4cd71767e2511554c20771
MD5 e75aedc8718bf16f6b329a3adac1c4d4
BLAKE2b-256 412399fa966b12377b77469a6184bd7deb8ed31f7b1b5fe7efd809019d4d237a

See more details on using hashes here.

File details

Details for the file Flask_ErrorsHandler-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: Flask_ErrorsHandler-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.6.5

File hashes

Hashes for Flask_ErrorsHandler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96e5957bf078fff1df0ace74f35c84afd350b0a2808e35bfd5a4628d27f0d3d8
MD5 7e31d2c8f91803be85093aff99f881a6
BLAKE2b-256 257ea4b8043bfa2199b9fe87b6deef651e4413152c764bb33dcca2355d5be402

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page