Closed andrzejd-pl closed 4 years ago
You stole my PR :) I will not create a new one, but I ask you to change the method:
public function parse($body)
{
$body = $this->stripBom($body);
if (empty($body))
return null;
$parsed = json_decode($body, $this->decode_as_array);
if (is_null($parsed) && 'null' !== strtolower($body)) {
$exceptionMessage = 'Unable to parse response as JSON';
if (function_exists('json_last_error_msg')) {
$jsonMessage = json_last_error_msg();
if ($jsonMessage !== false && $jsonMessage !== 'No error') {
$exceptionMessage .= ': ' . $jsonMessage;
}
}
throw new \Exception($exceptionMessage);
}
return $parsed;
}
in composer.json php>=5.3 - json_last_error_msg added at 5.5.0 json_last_error_msg can return FALSE or useless 'No error'
Finally dropped 5.* (18 months later) so json_last_error_msg
is fine now.
If response can not parse to json, should be throw precise exception (JsonParseException) instead universal exception.