src/Request.php
protected function parseBody($body, $status)
    {
        $this->lastResponse['body'] = json_decode($body, $this->returnType == self::RETURN_ASSOC);

        if ($status >= 200 && $status <= 299) {
            return $this->lastResponse['body'];
        }

        $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 SpotifyWebAPIAuthException($body->error_description, $status);
        } else {
            // Something went really wrong
            throw new SpotifyWebAPIException('An unknown error occurred.', $status);
        }
    }
protected function parseBody($body, $status)
    {
        $this->lastResponse['body'] = json_decode($body, $this->returnType == self::RETURN_ASSOC);

        if ($status >= 200 && $status <= 299) {
            return $this->lastResponse['body'];
        }

        $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 SpotifyWebAPIAuthException($body->error_description, $status);
        } else {
            // Something went really wrong
            throw new SpotifyWebAPIException('An unknown error occurred.', $status);
        }
    }
protected function parseBody ( $ body , $ status ) { $ this -> lastResponse [ 'body' ] = json_decode ( $ body , $ this -> returnType == self :: RETURN_ASSOC ) ; if ( $ status >= 200 && $ status <= 299 ) { return $ this -> lastResponse [ 'body' ] ; } $ 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 SpotifyWebAPIAuthException ( $ body -> error_description , $ status ) ; } else { // Something went really wrong throw new SpotifyWebAPIException ( 'An unknown error occurred.' , $ status ) ; } }
Parse the response body and handle API errors.

@param string $body The raw, unparsed response body.
@param int $status The HTTP status code, used to see if additional error handling is needed.

@throws SpotifyWebAPIException
@throws SpotifyWebAPIAuthException

@return array|object The parsed response body. Type is controlled by `Request::setReturnType()`.
Parse the response body and handle API errors .