fix: Always return response from _do_http_method #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Noticed a bug where the first time we queried an API after a long time (in this case Sierra), we'd see a json decode error coming from the requests modules
response.json()
. Since we weren't calling it on our end, I dug through the trace a little and found that we call.json()
in this library only when the token is expired and we do a refresh, which would explain the timing of the bug.So simply, make sure to return the raw response object when we do a token refresh.
Here's an example stacktrace of the bug we are encountering:
File /ereadingserver/./app/main.py, line 186, in login
File /ereadingserver/./app/auth/login.py, line 62, in log_in_with_card
File /ereadingserver/./app/sierra.py, line 106, in patron_is_valid
File /usr/local/lib/python3.10/site-packages/nypl_py_utils/classes/oauth2_api_client.py, line 63, in post
File /usr/local/lib/python3.10/site-packages/nypl_py_utils/classes/oauth2_api_client.py, line 106, in _do_http_method
File /usr/local/lib/python3.10/site-packages/requests/models.py, line 975, in json
I updated a quick test that would repro this!
https://jira.nypl.org/browse/PJR-788