Skip to content

Commit 81c8a12

Browse files
committed
Add reason argument to set_status() so that custom messages flow
Without adding a named argument of `reason` to tornado's `set_status()` method, messages associated with a thrown HTTPError will not be returned to the caller. Instead, the reason corresponding to the built-in status code is returned. In addition, because the reason argument is used, enforcement of a built in status code is skipped, thereby allowing for the optional use of non-builtin status codes. Updated the TestableJSONErrorsHandler class to have a compatible signature to Torado's `set_status()` method (to include the `reason` parameter). Fixes #283
1 parent c93958c commit 81c8a12

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ docs/_build/
5656
# PyBuilder
5757
target/
5858

59+
# PyCharm
60+
.idea/
61+
5962
.DS_Store
6063
.ipynb_checkpoints/

kernel_gateway/mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ def write_error(self, status_code, **kwargs):
125125
reply['reason'] = custom_reason
126126

127127
self.set_header('Content-Type', 'application/json')
128-
self.set_status(status_code)
128+
self.set_status(status_code, reason=reply['reason'])
129129
self.finish(json.dumps(reply))

kernel_gateway/tests/test_mixins.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,18 @@ def __init__(self):
137137
self.headers = {}
138138
self.response = None
139139
self.status_code = None
140+
self.reason = None
140141

141142
def finish(self, response):
142143
self.response = response
143144

144-
def set_status(self, status_code):
145+
def set_status(self, status_code, reason=None):
146+
# The reason parameter is essentially ignored, but necessary in the signature
147+
# in order for custom messages to be returned to the client from tornado.
148+
# Tornado's set_status method takes both parameters setting internal members
149+
# to both values. For now, we'll set the member but not use it.
145150
self.status_code = status_code
151+
self.reason = reason
146152

147153
def set_header(self, name, value):
148154
self.headers[name] = value

0 commit comments

Comments
 (0)