private function checkError(ResponseInterface $response, $url)
    {
        if (($response->getStatusCode() == 200) || ($response->getStatusCode() == 201)) {
            return;
        }

        switch ($response->getHeader('Content-Type')) {
            case 'text/plain':
                throw new \RuntimeException('Error: ' . $response->getBody() . ' URI: ' . $url);
            case 'application/json':
                $error = json_decode($response->getBody());
                if (isset($error->message)) {
                    throw new \RuntimeException($error->message . ' URI: ' . $url);
                }
                break;
            default:
                throw new \RuntimeException(
                    'Unknown Error: No error message was returned from the server - Code: ' . $response->getStatusCode(
                    ) . ' URI: ' . $url
                );
        }
    }
private function checkError(ResponseInterface $response, $url)
    {
        if (($response->getStatusCode() == 200) || ($response->getStatusCode() == 201)) {
            return;
        }

        switch ($response->getHeader('Content-Type')) {
            case 'text/plain':
                throw new \RuntimeException('Error: ' . $response->getBody() . ' URI: ' . $url);
            case 'application/json':
                $error = json_decode($response->getBody());
                if (isset($error->message)) {
                    throw new \RuntimeException($error->message . ' URI: ' . $url);
                }
                break;
            default:
                throw new \RuntimeException(
                    'Unknown Error: No error message was returned from the server - Code: ' . $response->getStatusCode(
                    ) . ' URI: ' . $url
                );
        }
    }
private function checkError ( ResponseInterface $ response , $ url ) { if ( ( $ response -> getStatusCode ( ) == 200 ) || ( $ response -> getStatusCode ( ) == 201 ) ) { return ; } switch ( $ response -> getHeader ( 'Content-Type' ) ) { case 'text/plain' : throw new \ RuntimeException ( 'Error: ' . $ response -> getBody ( ) . ' URI: ' . $ url ) ; case 'application/json' : $ error = json_decode ( $ response -> getBody ( ) ) ; if ( isset ( $ error -> message ) ) { throw new \ RuntimeException ( $ error -> message . ' URI: ' . $ url ) ; } break ; default : throw new \ RuntimeException ( 'Unknown Error: No error message was returned from the server - Code: ' . $ response -> getStatusCode ( ) . ' URI: ' . $ url ) ; } }
Check the response for an error.

@param ResponseInterface $response The response received.

@param string            $url      The request url.

@return void

@throws \RuntimeException On any error.
Check the response for an error .