-
Notifications
You must be signed in to change notification settings - Fork 111
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
fix decode error due to empty content #52
Conversation
src/DiscordClient.php
Outdated
$data = json_decode($response->getBody()->__toString()); | ||
// attempt to deserialize into JSON only if there is a content in the response | ||
$data = null; | ||
if ($response->getStatusCode() != 204) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, put {}'s around the if
src/DiscordClient.php
Outdated
// attempt to deserialize into JSON only if there is a content in the response | ||
$data = null; | ||
if ($response->getStatusCode() != 204) | ||
$data = json_decode($response->getBody()->__toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the spacing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure you follow PSR-2
thank for the review; changed has been applied accordingly |
Sometimes, Discord API can return response without body (HTTP 204 - No content).
This will result in the following stack exception since current code is always attempting to deserialize content into JSON :
The current commit is handling 204 response and ignoring JSON deserialization when there is no body.