Log the response body if the json_encode() fails. #658
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.
On 2 places (that I could find), if the
json_decode()
fails, the respone-body was logged in the exception that was thrown. Although, that was the intention.The PSR response
->getBody()->getContents()
is a stream, which needs to be rewinded before accessing (for a second time), just like is done when performing thejson_decode()
. This was not done when the exception was thrown, but the contents were requested again.This resulted in an exception without the actual response-body (it was empty).
I personally didn't feel like rewinding the stream again, so I decided to put the response-body in a separate variable and use that variable in the logging.
I also added some tests for it.
Let me know what you think, I'm open to feedback :)