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-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: Flask-ErrorsHandler-0.0.1.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-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3c341d695c5b0ba846ec6d8238cfa3ad7f1bf6ac8967bcdf4729f10fe247f099
MD5 598899b21492babddca90933a27d521b
BLAKE2b-256 8cd5026e47ad75d035a0491c3fb8b16f132008d839c7da5689986baf08c8fb9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Flask_ErrorsHandler-0.0.1-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-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9f519e6ea43ffb3ad6a7ccf957e90a738b3efd4f3869435da218e82133a7deb
MD5 6a5ff44e85eceaad9132a2920a14d319
BLAKE2b-256 b52dc9c99ec8dfdedbcee5f26039afa43b7cf04b7dda00408b712f32e45238f4

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