proxadmin/app/vmanager/errors.py

34 lines
1 KiB
Python
Raw Normal View History

2017-03-08 13:53:09 -05:00
from flask import render_template, request, jsonify
2017-03-08 19:55:12 -05:00
from . import vmanager
2017-03-08 13:53:09 -05:00
2017-03-08 19:55:12 -05:00
@vmanager.app_errorhandler(403)
2017-03-08 13:53:09 -05:00
def forbidden(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
response = jsonify({'error': 'forbidden'})
response.status_code = 403
return response
return render_template('403.html'), 403
2017-03-08 19:55:12 -05:00
@vmanager.app_errorhandler(404)
2017-03-08 13:53:09 -05:00
def page_not_found(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
response = jsonify({'error': 'not found'})
response.status_code = 404
return response
return render_template('404.html'), 404
2017-03-08 19:55:12 -05:00
@vmanager.app_errorhandler(500)
2017-03-08 13:53:09 -05:00
def internal_server_error(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
response = jsonify({'error': 'internal server error'})
response.status_code = 500
return response
return render_template('500.html'), 500