private function decodeResponse(ResponseInterface $response, RequestInterface $request)
    {
        if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
            // Handle Oauth specific authentication errors.
            if (401 === $response->getStatusCode()) {
                if (0 === strpos($request->getHeaderLine('Authorization'), 'Bearer')) {
                    throw new OauthAccessTokenAuthenticationException($request);
                }

                $parsedBody = [];
                parse_str((string) $request->getBody(), $parsedBody);
                if (array_key_exists('grant_type', $parsedBody) && 'refresh_token' === $parsedBody['grant_type']) {
                    throw new OauthRefreshTokenExpiredException($response, $request);
                }
            }
            throw new ClientErrorException($response, $request, (string) $response->getBody(), $response->getStatusCode(), null, $this->formatter);
        } elseif ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
            throw new ServerErrorException($response, $request, (string) $response->getBody(), $response->getStatusCode(), null, $this->formatter);
        }

        return $response;
    }
private function decodeResponse(ResponseInterface $response, RequestInterface $request)
    {
        if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
            // Handle Oauth specific authentication errors.
            if (401 === $response->getStatusCode()) {
                if (0 === strpos($request->getHeaderLine('Authorization'), 'Bearer')) {
                    throw new OauthAccessTokenAuthenticationException($request);
                }

                $parsedBody = [];
                parse_str((string) $request->getBody(), $parsedBody);
                if (array_key_exists('grant_type', $parsedBody) && 'refresh_token' === $parsedBody['grant_type']) {
                    throw new OauthRefreshTokenExpiredException($response, $request);
                }
            }
            throw new ClientErrorException($response, $request, (string) $response->getBody(), $response->getStatusCode(), null, $this->formatter);
        } elseif ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
            throw new ServerErrorException($response, $request, (string) $response->getBody(), $response->getStatusCode(), null, $this->formatter);
        }

        return $response;
    }
private function decodeResponse ( ResponseInterface $ response , RequestInterface $ request ) { if ( $ response -> getStatusCode ( ) >= 400 && $ response -> getStatusCode ( ) < 500 ) { // Handle Oauth specific authentication errors. if ( 401 === $ response -> getStatusCode ( ) ) { if ( 0 === strpos ( $ request -> getHeaderLine ( 'Authorization' ) , 'Bearer' ) ) { throw new OauthAccessTokenAuthenticationException ( $ request ) ; } $ parsedBody = [ ] ; parse_str ( ( string ) $ request -> getBody ( ) , $ parsedBody ) ; if ( array_key_exists ( 'grant_type' , $ parsedBody ) && 'refresh_token' === $ parsedBody [ 'grant_type' ] ) { throw new OauthRefreshTokenExpiredException ( $ response , $ request ) ; } } throw new ClientErrorException ( $ response , $ request , ( string ) $ response -> getBody ( ) , $ response -> getStatusCode ( ) , null , $ this -> formatter ) ; } elseif ( $ response -> getStatusCode ( ) >= 500 && $ response -> getStatusCode ( ) < 600 ) { throw new ServerErrorException ( $ response , $ request , ( string ) $ response -> getBody ( ) , $ response -> getStatusCode ( ) , null , $ this -> formatter ) ; } return $ response ; }
Throws one our of our exceptions if the API response code is higher than 399.

@param \Psr\Http\Message\ResponseInterface $response
@param \Psr\Http\Message\RequestInterface $request

@throws \Apigee\Edge\Exception\ClientErrorException
@throws \Apigee\Edge\Exception\ServerErrorException

@return \Psr\Http\Message\ResponseInterface
Throws one our of our exceptions if the API response code is higher than 399 .