Make API errors more informative

Fixes https://jira.coreos.com/browse/QUAY-999
This commit is contained in:
Joseph Schorr 2018-07-08 11:45:33 +03:00
parent beebe6d5ed
commit 4f152fd7c7
2 changed files with 9 additions and 9 deletions

View file

@ -19,7 +19,7 @@ DEFAULT_MESSAGE[409] = 'Conflict'
DEFAULT_MESSAGE[501] = 'Not Implemented'
def _abort(status_code, data_object, headers):
def _abort(status_code, data_object, description, headers):
# Add CORS headers to all errors
options_resp = current_app.make_default_options_response()
headers['Access-Control-Allow-Origin'] = '*'
@ -31,7 +31,7 @@ def _abort(status_code, data_object, headers):
# Report the abort to the user.
# Raising HTTPException as workaround for https://github.com/pallets/werkzeug/issues/1098
new_exception = HTTPException(response=resp)
new_exception = HTTPException(response=resp, description=description)
new_exception.code = status_code
raise new_exception
@ -42,11 +42,10 @@ def exact_abort(status_code, message=None):
if message is not None:
data['error'] = message
_abort(status_code, data, {})
_abort(status_code, data, message or None, {})
def abort(status_code, message=None, issue=None, headers=None, **kwargs):
message = (str(message) % kwargs if message else
DEFAULT_MESSAGE.get(status_code, ''))
@ -80,4 +79,4 @@ def abort(status_code, message=None, issue=None, headers=None, **kwargs):
if headers is None:
headers = {}
_abort(status_code, data, headers)
_abort(status_code, data, message, headers)