Skip to content

Commit

Permalink
Raise ValueError on invalid response body (#119)
Browse files Browse the repository at this point in the history
* Raise ValueError on empty response body

* Add log messaage on json decode ValueError

* Remove unused import from dev

* Use class logger object
  • Loading branch information
sarahbx authored and Northover committed Jan 2, 2018
1 parent 0a70d2d commit 0802953
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dyn/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,20 @@ def _handle_response(self, response, uri, method, raw_args, final):
if self.poll_incomplete:
response, body = self.poll_response(response, body)
self._last_response = response
ret_val = json.loads(body.decode('UTF-8'))

if not body:
err_msg_fmt = "Received Empty Response: {!r} status: {!r} {!r}"
error_message = err_msg_fmt.format(body, response.status, uri)
self.logger.error(error_message)
raise ValueError(error_message)

json_err_fmt = "Decode Error on Response Body: {!r} status: {!r} {!r}"
try:
ret_val = json.loads(body.decode('UTF-8'))
except ValueError:
self.logger.error(json_err_fmt.format(body, response.status, uri))
raise

if self.__call_cache is not None:
self.__call_cache.append((uri, method, clean_args(raw_args),
ret_val['status']))
Expand Down

0 comments on commit 0802953

Please sign in to comment.