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:
|
:return:
|
||||||
"""
|
"""
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
from werkzeug.exceptions import default_exceptions
|
from werkzeug.exceptions import HTTPException
|
||||||
from lemur.decorators import crossdomain
|
from lemur.decorators import crossdomain
|
||||||
if app.config.get('CORS'):
|
if app.config.get('CORS'):
|
||||||
@app.after_request
|
@app.after_request
|
||||||
|
@ -76,13 +76,11 @@ def configure_hook(app):
|
||||||
def after(response):
|
def after(response):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def make_json_handler(code):
|
@app.errorhandler(Exception)
|
||||||
def json_handler(error):
|
def handle_error(e):
|
||||||
metrics.send('{}_status_code'.format(code), 'counter', 1)
|
code = 500
|
||||||
response = jsonify(message=str(error))
|
if isinstance(e, HTTPException):
|
||||||
response.status_code = code
|
code = e.code
|
||||||
return response
|
|
||||||
return json_handler
|
|
||||||
|
|
||||||
for code, value in default_exceptions.items():
|
metrics.send('{}_status_code'.format(code), 'counter', 1)
|
||||||
app.error_handler_spec[None][code] = make_json_handler(code)
|
return jsonify(error=str(e)), code
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from lemur.authorities.views import * # noqa
|
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):
|
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 = [
|
install_requires = [
|
||||||
'Flask==0.10.1',
|
'Flask==0.11.1',
|
||||||
'Flask-RESTful==0.3.5',
|
'Flask-RESTful==0.3.5',
|
||||||
'Flask-SQLAlchemy==2.1',
|
'Flask-SQLAlchemy==2.1',
|
||||||
'Flask-Script==2.0.5',
|
'Flask-Script==2.0.5',
|
||||||
'Flask-Migrate==2.0.1',
|
'Flask-Migrate==2.0.0',
|
||||||
'Flask-Bcrypt==0.7.1',
|
'Flask-Bcrypt==0.7.1',
|
||||||
'Flask-Principal==0.4.0',
|
'Flask-Principal==0.4.0',
|
||||||
'Flask-Mail==0.9.1',
|
'Flask-Mail==0.9.1',
|
||||||
|
@ -52,14 +52,14 @@ install_requires = [
|
||||||
'marshmallow==2.4.0',
|
'marshmallow==2.4.0',
|
||||||
'pycrypto==2.6.1',
|
'pycrypto==2.6.1',
|
||||||
'cryptography==1.5',
|
'cryptography==1.5',
|
||||||
'pyopenssl==16.2.0',
|
'pyopenssl==16.1.0',
|
||||||
'pyjwt==1.4.2',
|
'pyjwt==1.4.2',
|
||||||
'xmltodict==0.10.2',
|
'xmltodict==0.10.2',
|
||||||
'lockfile==0.12.2',
|
'lockfile==0.12.2',
|
||||||
'inflection==0.3.1',
|
'inflection==0.3.1',
|
||||||
'future==0.16.0',
|
'future==0.16.0',
|
||||||
'boto==2.43.0', # we might make this optional
|
'boto==2.43.0', # we might make this optional
|
||||||
'boto3==1.4.0',
|
'boto3==1.4.1',
|
||||||
'acme==0.9.3',
|
'acme==0.9.3',
|
||||||
'retrying==1.3.3',
|
'retrying==1.3.3',
|
||||||
'tabulate==0.7.7',
|
'tabulate==0.7.7',
|
||||||
|
|
Loading…
Reference in New Issue