private function validateResponse($response) {
        if ($response->getStatusCode() !== 200) {
            $statusCode = $response->getStatusCode();
            throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
        } else if (strpos($response->getHeader('Content-Type')[0], 'application/json') === false) {
            throw new ServerException('Server did not respond with the expected content-type (application/json)');
        }

        try {
            $body = (string) $response->getBody();
            $json = json_decode($body, true);
            if (json_last_error()) {
                throw new ServerException(json_last_error_msg());
            }
        } catch (RuntimeException $e) {
            throw new ServerException($e->getMessage());
        }
    }
private function validateResponse($response) {
        if ($response->getStatusCode() !== 200) {
            $statusCode = $response->getStatusCode();
            throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
        } else if (strpos($response->getHeader('Content-Type')[0], 'application/json') === false) {
            throw new ServerException('Server did not respond with the expected content-type (application/json)');
        }

        try {
            $body = (string) $response->getBody();
            $json = json_decode($body, true);
            if (json_last_error()) {
                throw new ServerException(json_last_error_msg());
            }
        } catch (RuntimeException $e) {
            throw new ServerException($e->getMessage());
        }
    }
private function validateResponse ( $ response ) { if ( $ response -> getStatusCode ( ) !== 200 ) { $ statusCode = $ response -> getStatusCode ( ) ; throw new ServerException ( 'Server responded with HTTP status ' . $ statusCode , $ statusCode ) ; } else if ( strpos ( $ response -> getHeader ( 'Content-Type' ) [ 0 ] , 'application/json' ) === false ) { throw new ServerException ( 'Server did not respond with the expected content-type (application/json)' ) ; } try { $ body = ( string ) $ response -> getBody ( ) ; $ json = json_decode ( $ body , true ) ; if ( json_last_error ( ) ) { throw new ServerException ( json_last_error_msg ( ) ) ; } } catch ( RuntimeException $ e ) { throw new ServerException ( $ e -> getMessage ( ) ) ; } }
Validate the HTTP response and throw exceptions on errors

@param HttpResponse $response
@throws ServerException
Validate the HTTP response and throw exceptions on errors