@param  \Psr\Http\Message\ResponseInterface  $response
@param  array  $data

@throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException
552740
protected function checkResponse(ResponseInterface $response, $data)
    {
        if (! empty($data['error'])) {

            if (is_array($error = $data['error'])) {
                $code   = $error['code'];
                $error  = $error['message'];
            } else {
                $code   = 0;
                $error  = isset($data['error_description']) ? $data['error_description'] : $data['error'];
            }

            throw new IdentityProviderException($error, $code, $data);
        }
    }
9878
protected function handleNotJsonException(ResponseInterface $response)
    {
        if (true !== $response->hasHeader('Content-Type')
            || 'application/json' !== $response->getHeaderLine('Content-Type')
        ) {
            throw new ApiException(
                \sprintf(
                    'Waiting for json response but %s given',
                    $response->getHeaderLine('Content-Type')
                ),
                $this->getRequest(),
                $response
            );
        }
    }
279450
public function respondWithData(array $data)
    {

        $responseData = $this->getResponseStructure(true, $data, '');
        $response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
        return $response;
    }
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);
        }
    }
661811
public function updateResponseMsisdn($data_response = [])
    {
        try {
            if (isset($this->config[self::DETECTION_IS_SDP]) && $this->config[self::DETECTION_IS_SDP] === TRUE) {
                $inputParams = ['data_response' => $data_response,];
                $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
                // Sử dụng API: /api/v2/sdp/detection/update
                $updateResponseUrl       = $this->hostname . $this->config[self::API_UPDATE_SDP_DETECTION]['path'];
                $updateResponseSignature = md5($data_response['requestId'] . $this->config[self::API_UPDATE_SDP_DETECTION]['prefix'] . $data_response['responseData'] . $this->config[self::API_UPDATE_SDP_DETECTION]['prefix'] . $this->config[self::API_UPDATE_SDP_DETECTION]['token']);
                $updateResponseParams    = [
                    'requestId'    => $data_response['requestId'],
                    'responseData' => $data_response['responseData'],
                    'signature'    => $updateResponseSignature
                ];
                $this->debug->debug(__FUNCTION__, '$updateResponseUrl: ' . json_encode($updateResponseUrl));
                $this->debug->debug(__FUNCTION__, '$updateResponseSignature: ' . json_encode($updateResponseSignature));
                $this->debug->debug(__FUNCTION__, '$updateResponseParams: ' . json_encode($updateResponseParams));
                // Call API Update Detection
                $sendRequest = $this->requests->sendRequest($updateResponseUrl, $updateResponseParams);
                $this->debug->info(__FUNCTION__, '$sendRequest Result: ' . json_encode($sendRequest));
                if ($sendRequest != NULL) {
                    $resultRequest = json_decode(trim($sendRequest));
                    if (isset($resultRequest->result) && $resultRequest->result == 0) {
                        if (isset($resultRequest->phone_number) && !empty($resultRequest->phone_number)) {
                            $isMsisdn = trim($resultRequest->phone_number);
                            if ($this->nativeSession === TRUE) {
                                $this->debug->debug(__FUNCTION__, 'set native Session');
                                $this->debug->debug(__FUNCTION__, '$isMsisdn: ' . json_encode($isMsisdn));
                                Session::setUserdata(self::SESSION_MSISDN_DEFAULT, $isMsisdn);
                            }
                            $result = [
                                'status'       => 0,
                                'msisdn'       => $isMsisdn,
                                'data'         => isset($resultRequest->data) ? $resultRequest->data : NULL,
                                'session_data' => [
                                    'native_session'     => $this->nativeSession,
                                    'session_msisdn_key' => self::SESSION_MSISDN_DEFAULT
                                ]
                            ];
                        } else {
                            $result = [
                                'status' => 1,
                                'data'   => $resultRequest
                            ];
                        }
                    } else {
                        $result = [
                            'status' => 1,
                            'data'   => $resultRequest
                        ];
                    }
                    $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($result));

                    return $result;
                } else {
                    $this->debug->info(__FUNCTION__, '$sendRequest Result is Null');

                    return FALSE;
                }
            } else {
                $inputParams = ['data_response' => $data_response,];
                $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
                // Sử dụng API: /services/api/wap/v1/msisdn/update-response.html
                $updateResponseUrl       = $this->hostname . $this->config[self::API_UPDATE_REQUEST_MSISDN]['path'];
                $updateResponseSignature = md5($data_response['requestId'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['prefix'] . $data_response['responseData'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['prefix'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['token']);
                $updateResponseParams    = [
                    'requestId'    => $data_response['requestId'],
                    'responseData' => $data_response['responseData'],
                    'signature'    => $updateResponseSignature
                ];
                $this->debug->debug(__FUNCTION__, '$updateResponseUrl: ' . json_encode($updateResponseUrl));
                $this->debug->debug(__FUNCTION__, '$updateResponseSignature: ' . json_encode($updateResponseSignature));
                $this->debug->debug(__FUNCTION__, '$updateResponseParams: ' . json_encode($updateResponseParams));
                // Call API Update Detection
                $sendRequest = $this->requests->sendRequest($updateResponseUrl, $updateResponseParams);
                $this->debug->info(__FUNCTION__, '$sendRequest Result: ' . json_encode($sendRequest));
                if ($sendRequest != NULL) {
                    $resultRequest = json_decode(trim($sendRequest));
                    if (isset($resultRequest->Result) && $resultRequest->Result == 0) {
                        if (isset($resultRequest->MSISDN) && !empty($resultRequest->MSISDN)) {
                            $isMsisdn = trim($resultRequest->MSISDN);
                            if ($this->nativeSession === TRUE) {
                                $this->debug->debug(__FUNCTION__, 'set native Session');
                                $this->debug->debug(__FUNCTION__, '$isMsisdn: ' . json_encode($isMsisdn));
                                Session::setUserdata(self::SESSION_MSISDN_DEFAULT, $isMsisdn);
                            }
                            $result = [
                                'status'       => 0,
                                'msisdn'       => $isMsisdn,
                                'data'         => $resultRequest->Data,
                                'session_data' => [
                                    'native_session'     => $this->nativeSession,
                                    'session_msisdn_key' => self::SESSION_MSISDN_DEFAULT
                                ]
                            ];
                        } else {
                            $result = [
                                'status' => 1,
                                'data'   => $resultRequest
                            ];
                        }
                    } else {
                        $result = [
                            'status' => 1,
                            'data'   => $resultRequest
                        ];
                    }
                    $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($result));

                    return $result;
                } else {
                    $this->debug->info(__FUNCTION__, '$sendRequest Result is Null');

                    return FALSE;
                }
            }
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return NULL;
        }
    }
497377
protected function parseResponse(ResponseInterface $response)
    {
        $response = json_decode($response->getBody()->getContents());

        if (isset($response->success) && $response->success) {
            return $response->data;
        }

        throw new \Exception($response->error_info, $response->error_code);
    }
270865
protected function generateResponse(ResponseInterface $response): ArrivalBoardResponse
    {
        $json = $this->validateJson($response);
        if (isset($json['ArrivalBoard'])) {
            return ArrivalBoardResponse::createFromArray($json['ArrivalBoard']);
        }

        return new ArrivalBoardResponse();
    }
528582
public function intercept(ResponseInterface $response)
    {
        $this->getTransaction()->setResponse($response);
        $this->stopPropagation();
        RequestEvents::emitComplete($this->getTransaction());
    }
583612
private function decodeResponse(ResponseInterface $response)
    {
        $string = (string) $response->getBody();
        $data = json_decode($string, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonDecodeException($string);
        }

        return $data;
    }
1001860
protected function populateResponseWithData($data, Response $response, ?Producer\ProducerInterface $producer): Response
	{
		if ($producer !== null)
		{
			$stream = $producer->assemble($data);
			if ($stream instanceof StreamInterface)
			{
				$response = $response->withBody($stream);
			}
			if ($producer instanceof Producer\HeaderInterface)
			{
				foreach ($producer->assembleHeaders($data) as $name => $value)
				{
					$response = $response->withHeader($name, $value);
				}
			}
		}
		return $response;
	}
593041
protected function handleResponse(ResponseInterface $response)
    {
        $responseWrapper = new Response($response);
        $statusCode = (int) floor($response->getStatusCode() / 100);

        if ($statusCode === 4) {
            throw new ClientException($responseWrapper);
        } elseif ($statusCode === 5) {
            throw new ServerException($responseWrapper);
        }

        return $responseWrapper;
    }
1224513
private function sendHeaders(ResponseInterface $response)
    {
        // Set proper protocol, status code (and reason phrase) header
        if ($response->getReasonPhrase()) {
            header(sprintf(
                'HTTP/%s %d %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ));
        } else {
            header(sprintf(
                'HTTP/%s %d',
                $response->getProtocolVersion(),
                $response->getStatusCode()
            ));
        }

        // Loop through all headers
        foreach ($response->getHeaders() as $name => $values) {
            // Sanitize header name
            $name  = $this->sanitizeHeaderName($name);
            // First iteration, if more than one header with the same name
            // exists the $first parameter to the header method will indicate
            // if a second (etc) header should replace the previous one or
            // if multiple headers with the same name should be sent
            $first = true;
            foreach ($values as $value) {
                // Send header
                header(sprintf('%s: %s', $name, $value), $first);
                $first = false;
            }
        }
    }
722429
public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response)
    {
        if (!$this->verifyResourceRequest($request, $response, 'openid')) {
            return;
        }

        $token = $this->getToken();
        $claims = $this->userClaimsStorage->getUserClaims($token['user_id'], $token['scope']);
        // The sub Claim MUST always be returned in the UserInfo Response.
        // http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
        $claims += array(
            'sub' => $token['user_id'],
        );
        $response->addParameters($claims);
    }
40844
protected function checkResponse(ResponseInterface $response, $data)
    {
        if ($response->getStatusCode() >= 400) {
            $errorMessage = '';
            if (!empty($data['errors'])) {
                foreach ($data['errors'] as $error) {
                    if (!empty($errorMessage)) {
                        $errorMessage .= ' , ';
                    }
                    $errorMessage .= implode(' - ', $error);
                }
            } else {
                $errorMessage = $response->getReasonPhrase();
            }
            throw new IdentityProviderException(
                $errorMessage,
                $response->getStatusCode(),
                $response
            );
        }
    }
736451
protected function attachResponse($identity, $response, $key)
	{
		if ($identity instanceof Summoner)
		{
			$identity->set($key, $response);

			return true;
		}

		return false;
	}
719054
protected function createResourcesFromJsonData(array $data, ResponseInterface $response, ApiResourceInterface $owner)
    {
        $items = [];
        $className = $this->resourceClass();

        foreach ($data as $item) {
            $items[] = new $className($owner->getApi(), $item, $owner);
        }

        return $items;
    }
381436
public function respond(ResponseInterface $response)
    {
        // Send response
        if (!headers_sent()) {
            // Headers
            foreach ($response->getHeaders() as $name => $values) {
                $first = stripos($name, 'Set-Cookie') === 0 ? false : true;
                foreach ($values as $value) {
                    header(sprintf('%s: %s', $name, $value), $first);
                    $first = false;
                }
            }

            // Set the status _after_ the headers, because of PHP's "helpful" behavior with location headers.
            // See https://github.com/slimphp/Slim/issues/1730

            // Status
            header(sprintf(
                'HTTP/%s %s %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ), true, $response->getStatusCode());
        }

        // Body
        $request = $this->container->get('request');
        if (!$this->isEmptyResponse($response) && !$this->isHeadRequest($request)) {
            $body = $response->getBody();
            if ($body->isSeekable()) {
                $body->rewind();
            }
            $settings = $this->container->get('settings');
            $chunkSize = $settings['responseChunkSize'];

            $contentLength = $response->getHeaderLine('Content-Length');
            if (!$contentLength) {
                $contentLength = $body->getSize();
            }


            if (isset($contentLength)) {
                $amountToRead = $contentLength;
                while ($amountToRead > 0 && !$body->eof()) {
                    $data = $body->read(min((int)$chunkSize, (int)$amountToRead));
                    echo $data;

                    $amountToRead -= strlen($data);

                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            } else {
                while (!$body->eof()) {
                    echo $body->read((int)$chunkSize);
                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            }
        }
    }