bigcommerce-api-php icon indicating copy to clipboard operation
bigcommerce-api-php copied to clipboard

Exception when handling 404 responses with JSON content in body

Open bc-ravijayaramappa opened this issue 9 years ago • 1 comments

Connection.php L212 If the response body of a request with 404 status has JSON content, the library throws an exception instead of ClientError.

Cause: Connection::handleResponse() decodes the response body without checking the response status and then tries to create a ClientError object using the decoded response body object. ClientError is expecting a string as argument but gets an object instead and thus throws an Error

bc-ravijayaramappa avatar Apr 27 '15 21:04 bc-ravijayaramappa

Wow this is old. I got the same issue (but with a different error). Whenever the body is not JSON and you're using JSON, it will pass an incorrect argument to ClientError and crash. This does not happen if you're using Xml, as the body is returned raw.

This could be easily fixed by calling json_decode after the status check. I can make a pull request

Y0lk avatar Jul 11 '18 17:07 Y0lk