Set reason on HTTP errors, None otherwise.

This commit is contained in:
Kevin Bates 2017-10-31 10:40:50 -07:00
parent b24aa5e023
commit ed3b0e4594

View File

@ -461,16 +461,16 @@ class APIHandler(IPythonHandler):
message = responses.get(status_code, 'Unknown HTTP Error') message = responses.get(status_code, 'Unknown HTTP Error')
reply = { reply = {
'message': message, 'message': message,
# some clients expect 'reason' to exist and equate to status_code text
'reason': message,
} }
exc_info = kwargs.get('exc_info') exc_info = kwargs.get('exc_info')
if exc_info: if exc_info:
e = exc_info[1] e = exc_info[1]
if isinstance(e, HTTPError): if isinstance(e, HTTPError):
reply['message'] = e.log_message or message reply['message'] = e.log_message or message
reply['reason'] = e.reason
else: else:
reply['message'] = 'Unhandled error' reply['message'] = 'Unhandled error'
reply['reason'] = None
reply['traceback'] = ''.join(traceback.format_exception(*exc_info)) reply['traceback'] = ''.join(traceback.format_exception(*exc_info))
self.log.warning(reply['message']) self.log.warning(reply['message'])
self.finish(json.dumps(reply)) self.finish(json.dumps(reply))