Closed padamstx closed 1 year ago
I pushed a commit that implements @ricellis's suggestion to throw an ApiException with the JSONDecodeError as the "caused by".
Note: I'm going to hold off merging this until @ricellis's team has a chance to test with it.
@padamstx For error responses, ApiException
tries to parse the response as JSON and if there's an exception during parsing it'll return response.text
: https://github.com/IBM/python-sdk-core/blob/main/ibm_cloud_sdk_core/api_exception.py#L75
I'm wondering if it's worth updating this logic to be similar to what you've done for handling malformed JSON in success responses.
@padamstx For error responses,
ApiException
tries to parse the response as JSON and if there's an exception during parsing it'll returnresponse.text
: https://github.com/IBM/python-sdk-core/blob/main/ibm_cloud_sdk_core/api_exception.py#L75 I'm wondering if it's worth updating this logic to be similar to what you've done for handling malformed JSON in success responses.
Yes, I considered this but decided against it because we're already in the process of building an ApiException to reflect an actual error that was returned by the server (e.g. 400 Bad Request), so I didn't think the resulting JSONDecodeError should take precedence over that.
:tada: This PR is included in version 3.16.3 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
This commit fixes BaseService.send() so that it will now detect a JSON parsing error when processing a success (2xx) response. If, in fact, a JSON parsing error occurs while trying to process a JSON response body, then a requests.exceptions.JSONDecodeError is raised and propagated back to the caller.