Add issue URLs to most errors. The corresponding issue pages will be checked into the public docs repo

This commit is contained in:
Joseph Schorr 2014-01-28 18:29:45 -05:00
parent c7e616edb9
commit 2b134158f5
3 changed files with 66 additions and 32 deletions

View file

@ -13,8 +13,9 @@ DEFAULT_MESSAGE[401] = 'Unauthorized'
DEFAULT_MESSAGE[403] = 'Permission Denied'
DEFAULT_MESSAGE[404] = 'Not Found'
DEFAULT_MESSAGE[409] = 'Conflict'
DEFAULT_MESSAGE[501] = 'Not Implemented'
def abort(status_code, message=None, **kwargs):
def abort(status_code, message=None, issue=None, **kwargs):
message = (str(message) % kwargs if message else
DEFAULT_MESSAGE.get(status_code, ''))
@ -38,7 +39,21 @@ def abort(status_code, message=None, **kwargs):
# Log the abort.
logger.error('Error %s: %s; Arguments: %s' % (status_code, message, params))
resp = jsonify({'error': message})
# Calculate the issue URL (if the issue ID was supplied).
issue_url = None
if issue:
issue_url = 'http://devtable.github.io/quaydocs/issues/%s.html' % (issue)
# Create the final response data and message.
data = {}
if issue_url:
data['info_url'] = issue_url
message = message + '. For more information: ' + issue_url
data['error'] = message
resp = jsonify(data)
resp.status_code = status_code
# Report the abort to the user.