Skip to content

Commit

Permalink
Log response when debug level is set (#320)
Browse files Browse the repository at this point in the history
* Log response when debug level is set

* log at different place

* change log statement

* Log response when debug level is set

* log at different place

* change log statement

* chore/enhance-debug-logging

* refactor- check response is not None in single place

* log only non-stream response

* log hardcoded message for streamed content

* log at info instead of error

* log response status @ info, data @ debug

Co-authored-by: Tim Abramson <tim.abramson@code42.com>
  • Loading branch information
kiran-chaudhary and timabrmsn committed May 12, 2021
1 parent e9522eb commit 401cd38
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/py42/services/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,23 @@ def request(
proxies=proxies or settings.proxies,
)

if not stream and response is not None:
# setting this manually speeds up read times
response.encoding = u"utf-8"

if response is not None and 200 <= response.status_code <= 399:
return Py42Response(response)

if response is not None and response.status_code == 401:
if isinstance(self._auth, C42RenewableAuth):
self._auth.clear_credentials()
if response is not None:
debug.logger.info(u"Response status: {}".format(response.status_code))
if not stream:
# setting this manually speeds up read times
response.encoding = u"utf-8"
debug.logger.debug(u"Response data: {}".format(response.text))
else:
debug.logger.debug(u"Response data: <streamed>")

if 200 <= response.status_code <= 399:
return Py42Response(response)

if response.status_code == 401:
if isinstance(self._auth, C42RenewableAuth):
self._auth.clear_credentials()
else:
debug.logger.debug(u"Error! Could not retrieve response.")

# if nothing has been returned after two attempts, something went wrong
_handle_error(method, url, response)
Expand Down

0 comments on commit 401cd38

Please sign in to comment.