git.fiddlerwoaroof.com
Browse code

set server to always return reponse code 200, added hook to set alternative response code

Ed L authored on 20/10/2011 18:45:37
Showing 1 changed files
... ...
@@ -77,6 +77,13 @@ class ServerEvents(object):
77 77
 		'''Given the freshly decoded content of the request, return what content should be used'''
78 78
 		return content
79 79
 
80
+	def setResponseCode(self, result, request):
81
+		code = 200
82
+		#if not isinstance(result, list):
83
+		#	if result is not None and result.error is not None:
84
+		#		code = result.error.code or 500
85
+		request.setResponseCode(code)
86
+
80 87
 
81 88
 
82 89
 ## Base class providing a JSON-RPC 2.0 implementation with 2 customizable hooks
... ...
@@ -174,17 +181,10 @@ class JSON_RPC(Resource):
174 181
 		return deferreds
175 182
 
176 183
 
177
-	def _setresponseCode(self, result, request):
178
-		code = 200
179
-		if not isinstance(result, list):
180
-			if result is not None and result.error is not None:
181
-				code = 500
182
-		request.setResponseCode(code)
183
-
184 184
 	def _cbRender(self, result, request):
185 185
 		@threads.deferToThread
186 186
 		def _inner(*args, **_):
187
-			self._setresponseCode(result, request)
187
+			self.eventhandler.setResponseCode(result, request)
188 188
 			self.eventhandler.log(result, request, error=False)
189 189
 			if result is not None:
190 190
 				request.setHeader("content-type", 'application/json')
... ...
@@ -206,7 +206,7 @@ class JSON_RPC(Resource):
206 206
 			else: err = result
207 207
 
208 208
 			err = self.render_error(err, id)
209
-			self._setresponseCode(err, request)
209
+			self.eventhandler.setResponseCode(err, request)
210 210
 
211 211
 			request.setHeader("content-type", 'application/json')
212 212
 			result_ = jsonrpc.jsonutil.encode(err).encode('utf-8')