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;
    }