Customizable 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, for web that returns html page or JSON if request is XHR, or you can register custom handlers for blueprint or the entire app.
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['ERROR_PAGE'] = 'error.html'
error = ErrorHandler(app)
custom = Blueprint('custom', __name__)
web = Blueprint('web', __name__)
error.api_register(app)
error.web_register(web)
@error.register(custom)
def error_handler(exc):
return str(exc), 500, {'Content-Type': 'text/plain'}
@app.route('/api')
def index():
abort(500, 'Error from app')
@web.route('/web')
def index():
abort(500, 'Error from web blueprint')
@custom.route('/custom')
def index():
abort(500, 'Error from custom 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 Go to http://127.0.0.1:5000/custom and see error message response as a plain text
Configuration
ERROR_PAGE: (default: None) path of html template to use for show error message
ERROR_DEFAULT_MSG: (default: Unhandled Exception) default message for unhandled exceptions
License MIT
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
Built Distribution
File details
Details for the file Flask-ErrorsHandler-2.0.0.tar.gz
.
File metadata
- Download URL: Flask-ErrorsHandler-2.0.0.tar.gz
- Upload date:
- Size: 4.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 837e3eeb5cc70faa9ae8797e2e2ccd12d326bc2e62f3dd24d004c638a0747e4f |
|
MD5 | fac71f3128cdd62a560576943a9378ba |
|
BLAKE2b-256 | 69eef5164aa4ac3fc66c1d22ada01c07c66f460e094f2d31de6f4d8652487abf |
File details
Details for the file Flask_ErrorsHandler-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_ErrorsHandler-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a5fabe56768b41bc223c5bbbe31f99201075c2b3ff927a478833ffb3ef4a8cd |
|
MD5 | add14812c619ee00b0a2e4e4927ea0f0 |
|
BLAKE2b-256 | 4e3cd6737e118da954375a16c70c67f9a0530f80ad2acc5793be66c7db835510 |