-
Notifications
You must be signed in to change notification settings - Fork 138
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
Problem with JSON parsing #48
Comments
@josler Can you have a look at this? The response is indeed not a valid JSON. |
Thanks @frankmichel. @nurazem @josler Ideally the server shouldn't return a whitespace artifact, but because the events resource doesn't return JSON the client shouldn't be looking for any on a 2xx response. Looks like the client will need a patch, marking as a bug. |
Hi @dehora. I have looked into the issue and I think that the problem is on the server side. Although, the resource doesn't return JSON, the response's Content-Type header is set to 'application/json'. As you can see below Guzzle is trying to parse the body based on that header. public function parse(CommandInterface $command)
{
$response = $command->getRequest()->getResponse();
// Account for hard coded content-type values specified in service descriptions
if ($contentType = $command['command.expects']) {
$response->setHeader('Content-Type', $contentType);
} else {
$contentType = (string) $response->getHeader('Content-Type');
}
return $this->handleParsing($command, $response, $contentType);
}
protected function handleParsing(CommandInterface $command, Response $response, $contentType)
{
$result = $response;
if ($result->getBody()) {
if (stripos($contentType, 'json') !== false) {
$result = $result->json();
} elseif (stripos($contentType, 'xml') !== false) {
$result = $result->xml();
}
}
return $result;
} |
I am experiencing this bug as well. |
Yep, me too. |
Hey @josler @nurazem what's the ETA on fixing this? It is pretty easy to repeat and is a showstopper:
Yields this:
Guzzle 4.2.3 |
Fixed with v1.0.0-b4! Thanks. |
A call to https://api.intercom.io/events returns a 202 response with an empty " " space in it. This causes issues with Guzzle since it cannot be parsed as json:
{"error":{"type":"Guzzle\Common\Exception\RuntimeException","message":"Unable to parse response body into JSON: 4","file":"/home/vagrant/myapp/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php","line":861}}
The text was updated successfully, but these errors were encountered: