Creates client exception from response.

@param  ResponseInterface $response
@param  string $data Parsed response data

@return IdentityProviderException
168681
public static function clientException(ResponseInterface $response, $data)
    {
        $message = $response->getReasonPhrase();
        $code = $response->getStatusCode();
        $body = (string) $response->getBody();

        if (isset($data['meta'], $data['meta']['error_message'])) {
            $message = $data['meta']['error_message'];
        }
        if (isset($data['meta'], $data['meta']['code'])) {
            $code = $data['meta']['code'];
        }

        return new static($message, $code, $body);
    }
66890
protected function checkResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() >= 400) {
            $message = sprintf(
                "Something went wrong when calling Vault (%s - %s)\n%s.",
                $response->getStatusCode(),
                $response->getReasonPhrase(),
                $response->getBody()->getContents()
            );

            if ($response->getStatusCode() >= 500) {
                throw new ServerException($message, $response->getStatusCode(), $response);
            }

            throw new ClientException($message, $response->getStatusCode(), $response);
        }
    }
1045387
private function withError(ResponseInterface $response, $throwable)
    {
        if ($throwable instanceof ErrorException) {
            $severity = ErrorHandler::getErrorType($throwable->getSeverity());
        } else {
            $severity = 'Error';
        }

        $contents = [
            'message' => 'Application Error',
            'status' => 500,
            'severity' => $severity,
            'throwable' => $throwable,
        ];

        if ($this->displayErrorDetails) {
            $throwables = $this->unpackThrowables($throwable);
            $contents['details'] = $this->formatStacktraceForExceptions($throwables);
            $contents['message'] = $throwable->getMessage();
        }

        return $this
            ->withHTML($response, $contents)
            ->withStatus(500);
    }
417976
protected function checkResponse(ResponseInterface $response, $data)
  {
    if($response->getStatusCode() != 200 || !is_array($data))
    {
      $data = ValueAs::arr($data);
      $msg = Arrays::value($data, 'message', 'An unknown error occurred');
      throw new IdentityProviderException($msg, $response->getStatusCode(), $data);
    }
  }
1319142
public static function create(
      RequestInterface $request,
      ResponseInterface $response = null,
      \Exception $previous = null,
      array $ctx = []
    ) {
        $e = parent::create($request, $response, $previous);
        if ($response === null) {
            return $e;
        }

        // Re-create the exception to alter the message.
        $details = self::getErrorDetails($response);
        if (!empty($details)) {
            $className = get_class($e);
            $e = new $className($e->getMessage() . $details, $e->getRequest(), $e->getResponse());
        }

        return $e;
    }
852695
protected function checkResponse(ResponseInterface $response, $data)
    {

        if (!empty($data['errors'])) {
            $errors = $data['errors'];
            throw new ResponseException($errors);
        }

        parent::checkResponse($response, $data);
    }
1182949
protected function checkResponse(ResponseInterface $response, $data)
    {
        $acceptableStatuses = [200, 201];

        if (!in_array($response->getStatusCode(), $acceptableStatuses)) {
            throw new IdentityProviderException(
                $data['message'] ?: $response->getReasonPhrase(),
                $response->getStatusCode(),
                $response
            );
        }
    }
969096
private function createResponse($curl, $data, InternalRequestInterface $internalRequest)
    {
        if (empty($data)) {
            throw HttpAdapterException::cannotFetchUri(
                (string) $internalRequest->getUri(),
                $this->getName(),
                curl_error($curl)
            );
        }

        $headers = substr($data, 0, $headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE));

        return $this->getConfiguration()->getMessageFactory()->createResponse(
            StatusCodeExtractor::extract($headers),
            ProtocolVersionExtractor::extract($headers),
            HeadersNormalizer::normalize($headers),
            BodyNormalizer::normalize(substr($data, $headersSize), $internalRequest->getMethod())
        );
    }
1299768
protected function checkResponse(ResponseInterface $response, $data)
    {
        $exception = null;

        if (isset($data['errors'])) {
            foreach ($data['errors'] as $error) {
                $exception = new YextException($error['message'], $error['errorCode'], $exception);
            }
        }

        if ($exception != null) {
            throw $exception;
        }
    }
693862
protected function populateResponseWithException(
		Exception\HttpCode $exception, Response $response, ?Producer\ProducerInterface $producer
	): Response
	{
		$response = $this->populateResponseWithData($exception->getPayload(), $response, $producer);
		if ($exception instanceof Exception\HeaderInterface)
		{
			foreach ($exception->getHeaders() as $name => $value)
			{
				$response = $response->withHeader($name, $value);
			}
		}
		$response = $response->withStatus($exception->getCode(), $exception->getMessage());
		return $response;
	}
233884
function createResponse(\Psr\Http\Message\ResponseInterface $response)
    {
        return WirecardResponse::fromHttpResponse(
            $response,
            $this->resultClass
        );
    }
245063
public static function factory(RequestInterface $request, Response $response)
    {
        $message = 'Client error response' . PHP_EOL . implode(PHP_EOL, array(
            '[status code] ' . $response->getStatusCode(),
            '[reason phrase] ' . $response->getReasonPhrase(),
            '[url] ' . $request->getUrl(),
        ));

        $e = new static($message);
        $e->setResponse($response);
        $e->setRequest($request);

        return $e;
    }
311169
private function validateResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() !== 200) {
            $responseData = json_decode((string) $response->getBody(), true);
            $code = isset($responseData['error']['code']) ? $responseData['error']['code'] : 0;
            $message = isset($responseData['error']['message']) ? $responseData['error']['message'] : $response->getReasonPhrase();

            throw new ApiException($message, $code, $responseData);
        }
    }
1183736
protected function processResponse(Response $response)
    {
        if ($response->hasErrors()) {
            throw new \Exception($this->getErrorMessage($response));
        }

        return is_array($response->body) ? $response->body['data'] : $response->body->data;
    }
1051513
protected function checkResponse(ResponseInterface $response, $data)
    {
        if ($response->getStatusCode() >= 400) {
            throw DiscordIdentityProviderException::clientException($response, $data);
        }
    }
578021
protected function decodeBody(Response $response)
    {
        if ($response->isServerError()) {
            throw new Exception\ClientException(sprintf(
                "'%s' provider encountered a '%s' error while querying '%s'",
                $this->getIdentifier(),
                $response->getReasonPhrase(),
                $this->uri
            ));
        }

        $body = Json::decode($response->getBody());

        if ($response->isClientError()) {
            throw new Exception\ClientException($body->error->message, $response->getStatusCode());
        }

        return $body;
    }
996545
public static function clientException(ResponseInterface $response, $data)
    {
        return static::fromResponse(
            $response,
            isset($data['message']) ? $data['message'] : $response->getReasonPhrase()
        );
    }