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

Log the response body if the json_encode() fails. #658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aaajeetee
Copy link

@aaajeetee aaajeetee commented Sep 9, 2024

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 the json_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 :)

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

Successfully merging this pull request may close these issues.

1 participant