Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove error logging when non-json response is received #4

Open
geoff-va opened this issue Jun 8, 2023 · 0 comments
Open

Remove error logging when non-json response is received #4

geoff-va opened this issue Jun 8, 2023 · 0 comments

Comments

@geoff-va
Copy link
Contributor

geoff-va commented Jun 8, 2023

When a request comes back with a status of ok but the response body is empty or not json, an error is logged.

This is deceiving because we have APIs that don't return a body - only a 200 or 201.

Example:

ibl_local_lms  | 2023-06-08 17:00:13,174 INFO 7 [ibl_request_router.views] [user 5] [ip 69.129.255.173] views.py:51 - Response core/users/platforms/: 201
ibl_local_lms  | 2023-06-08 17:00:13,175 ERROR 7 [ibl_request_router.views] [user 5] [ip 69.129.255.173] views.py:58 - Non-JSON response core/users/platforms/: 201
ibl_local_lms  | Traceback (most recent call last):
ibl_local_lms  |   File "/openedx/venv/lib/python3.8/site-packages/requests/models.py", line 971, in json
ibl_local_lms  |     return complexjson.loads(self.text, **kwargs)
ibl_local_lms  |   File "/openedx/venv/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
ibl_local_lms  |     return _default_decoder.decode(s)
ibl_local_lms  |   File "/openedx/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
ibl_local_lms  |     obj, end = self.raw_decode(s)
ibl_local_lms  |   File "/openedx/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
ibl_local_lms  |     return self.scan_once(s, idx=_w(s, idx).end())
ibl_local_lms  | simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
ibl_local_lms  |
ibl_local_lms  | During handling of the above exception, another exception occurred:
ibl_local_lms  |
ibl_local_lms  | Traceback (most recent call last):
ibl_local_lms  |   File "/openedx/requirements/ibl-edx-request-router-app-0.2.5/src/ibl_request_router/views.py", line 53, in manager_proxy_view
ibl_local_lms  |     response.json(), status=response.status_code
ibl_local_lms  |   File "/openedx/venv/lib/python3.8/site-packages/requests/models.py", line 975, in json
ibl_local_lms  |     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
ibl_local_lms  | requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

We've already logged the response as text, so there's no reason to log that the response wasn't json, I don't think. At the very least we should remove the exc_info=True from the log and it should probably be a warning and not error (since it's not an error - not every API is going to return a JSON body).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant