From b24aa5e0235a0c70a41a3b22c5b8d5f069710b86 Mon Sep 17 00:00:00 2001 From: Kevin Bates Date: Thu, 19 Oct 2017 08:03:52 -0700 Subject: [PATCH 1/2] Add 'reason' field to JSON error responses During the deprecation/removal of the `@json_errors` decorator, the `reason` field was not carried forward into the compatible replacement method `APIHandler.write_error`. This broke some client (tests) that relied on that field's presence. Fixes #2957. --- notebook/base/handlers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index d5a738251..32b96f895 100755 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -461,6 +461,8 @@ class APIHandler(IPythonHandler): message = responses.get(status_code, 'Unknown HTTP Error') reply = { 'message': message, + # some clients expect 'reason' to exist and equate to status_code text + 'reason': message, } exc_info = kwargs.get('exc_info') if exc_info: From ed3b0e45943b7f21543ea194b7eac9fd3cd42ca5 Mon Sep 17 00:00:00 2001 From: Kevin Bates Date: Tue, 31 Oct 2017 10:40:50 -0700 Subject: [PATCH 2/2] Set reason on HTTP errors, None otherwise. --- notebook/base/handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index 32b96f895..696bdd00f 100755 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -461,16 +461,16 @@ class APIHandler(IPythonHandler): message = responses.get(status_code, 'Unknown HTTP Error') reply = { 'message': message, - # some clients expect 'reason' to exist and equate to status_code text - 'reason': message, } exc_info = kwargs.get('exc_info') if exc_info: e = exc_info[1] if isinstance(e, HTTPError): reply['message'] = e.log_message or message + reply['reason'] = e.reason else: reply['message'] = 'Unhandled error' + reply['reason'] = None reply['traceback'] = ''.join(traceback.format_exception(*exc_info)) self.log.warning(reply['message']) self.finish(json.dumps(reply))