teaking the way exceptions are handled (#519)
This commit is contained in:
parent
b3aa057d58
commit
12ae0a587d
@ -68,7 +68,7 @@ def configure_hook(app):
|
||||
:return:
|
||||
"""
|
||||
from flask import jsonify
|
||||
from werkzeug.exceptions import default_exceptions
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from lemur.decorators import crossdomain
|
||||
if app.config.get('CORS'):
|
||||
@app.after_request
|
||||
@ -76,13 +76,11 @@ def configure_hook(app):
|
||||
def after(response):
|
||||
return response
|
||||
|
||||
def make_json_handler(code):
|
||||
def json_handler(error):
|
||||
metrics.send('{}_status_code'.format(code), 'counter', 1)
|
||||
response = jsonify(message=str(error))
|
||||
response.status_code = code
|
||||
return response
|
||||
return json_handler
|
||||
@app.errorhandler(Exception)
|
||||
def handle_error(e):
|
||||
code = 500
|
||||
if isinstance(e, HTTPException):
|
||||
code = e.code
|
||||
|
||||
for code, value in default_exceptions.items():
|
||||
app.error_handler_spec[None][code] = make_json_handler(code)
|
||||
metrics.send('{}_status_code'.format(code), 'counter', 1)
|
||||
return jsonify(error=str(e)), code
|
||||
|
@ -2,7 +2,7 @@
|
||||
import pytest
|
||||
from lemur.authorities.views import * # noqa
|
||||
|
||||
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
|
||||
from lemur.tests.vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
|
||||
|
||||
|
||||
def test_authority_input_schema(client, role):
|
||||
|
8
setup.py
8
setup.py
@ -34,11 +34,11 @@ with open(os.path.join(ROOT, "lemur", "__about__.py")) as f:
|
||||
|
||||
|
||||
install_requires = [
|
||||
'Flask==0.10.1',
|
||||
'Flask==0.11.1',
|
||||
'Flask-RESTful==0.3.5',
|
||||
'Flask-SQLAlchemy==2.1',
|
||||
'Flask-Script==2.0.5',
|
||||
'Flask-Migrate==2.0.1',
|
||||
'Flask-Migrate==2.0.0',
|
||||
'Flask-Bcrypt==0.7.1',
|
||||
'Flask-Principal==0.4.0',
|
||||
'Flask-Mail==0.9.1',
|
||||
@ -52,14 +52,14 @@ install_requires = [
|
||||
'marshmallow==2.4.0',
|
||||
'pycrypto==2.6.1',
|
||||
'cryptography==1.5',
|
||||
'pyopenssl==16.2.0',
|
||||
'pyopenssl==16.1.0',
|
||||
'pyjwt==1.4.2',
|
||||
'xmltodict==0.10.2',
|
||||
'lockfile==0.12.2',
|
||||
'inflection==0.3.1',
|
||||
'future==0.16.0',
|
||||
'boto==2.43.0', # we might make this optional
|
||||
'boto3==1.4.0',
|
||||
'boto3==1.4.1',
|
||||
'acme==0.9.3',
|
||||
'retrying==1.3.3',
|
||||
'tabulate==0.7.7',
|
||||
|
Loading…
Reference in New Issue
Block a user