protected parseBody ( string $body, integer $status ) : array | object | ||
$body | string | The raw, unparsed response body. |
$status | integer | The HTTP status code, used to see if additional error handling is needed. |
return | array | object | The parsed response body. Type is controlled by Request::setReturnAssoc(). |
protected function parseBody($body, $status)
{
if ($status >= 200 && $status <= 299) {
return json_decode($body, $this->returnAssoc);
}
$body = json_decode($body);
$error = isset($body->error) ? $body->error : null;
if (isset($error->message) && isset($error->status)) {
// API call error
throw new SpotifyWebAPIException($error->message, $error->status);
} elseif (isset($body->error_description)) {
// Auth call error
throw new SpotifyWebAPIException($body->error_description, $status);
} else {
// Something went really wrong
throw new SpotifyWebAPIException('An unknown error occurred.', $status);
}
}