Skip to content

Commit a28cd02

Browse files
committed
resources, dont change error response handling
bring back old way of handling errors, updating error handling for new PR
1 parent e477c7e commit a28cd02

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

scrapyrt/resources.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ def handle_error(self, exception_or_failure, request):
5757
:return: dict which will be converted to JSON error response
5858
5959
"""
60+
failure = None
6061
if isinstance(exception_or_failure, Exception):
6162
exception = exception_or_failure
6263
elif isinstance(exception_or_failure, Failure):
6364
exception = exception_or_failure.value
65+
failure = exception_or_failure
6466
else:
6567
raise TypeError(
6668
'Expected Exception or {} instances, got {}'.format(
@@ -77,7 +79,7 @@ def handle_error(self, exception_or_failure, request):
7779
else:
7880
request.setResponseCode(500)
7981
if request.code == 500:
80-
log.err(f'Error when rendering response: "{exception}"')
82+
log.err(failure)
8183
return self.format_error_response(exception, request)
8284

8385
def format_error_response(self, exception, request):
@@ -86,18 +88,14 @@ def format_error_response(self, exception, request):
8688
# and they fail on str(exception) call.
8789
msg = exception.message if hasattr(exception, 'message') else str(exception)
8890

89-
encoded_error_response = self.json_encoder.encode({
91+
return {
9092
"status": "error",
9193
"message": msg,
9294
"code": request.code
93-
}) + "\n"
94-
return encoded_error_response.encode('utf8')
95+
}
9596

9697
def render_object(self, obj, request):
97-
try:
98-
r = self.json_encoder.encode(obj) + "\n"
99-
except Exception as exc:
100-
return self.handle_error(exc, request)
98+
r = self.json_encoder.encode(obj) + "\n"
10199

102100
request.setHeader('Content-Type', 'application/json')
103101
request.setHeader('Access-Control-Allow-Origin', '*')

0 commit comments

Comments
 (0)