Receive server's response

This method validates `$response`'s status

@param HTTP_Request2_Response $response Response from server

@return void
8703
protected function processResponse(HTTP_Request2_Response $response): void
    {
        $status = $response->getStatus();
        $reasonPhrase = $response->getReasonPhrase();
        $this->log("Response status: $status", Project::MSG_DEBUG);
        $this->log("Response reason: $reasonPhrase", Project::MSG_DEBUG);

        if ($status !== VisualizerTask::STATUS_OK) {
            $message = "Request unsuccessful. Response from server: $status $reasonPhrase";
            $this->log($message, Project::MSG_ERR);
            throw new BuildException($message);
        }
    }
1065864
private static function handleErrors($response)
    {
        switch ($response->getStatusCode()) {
            case 200:
                return json_decode($response->getBody());
                break;
            case 401:
                throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient permissions)');
                break;
            case 404:
                throw new NotFoundException('Object not found within your account scope');
                break;
            case 406:
                throw new InvalidFormatException('Requested format is not supported - request JSON or XML only');
                break;
            case 422:
                throw new ValidationException('Validation error(s) for create or update method');
                break;
            case 500:
                throw new ServerException('Something went wrong on Challonge\'s end');
                break;
            default:
                $decodedResponse = json_decode($response->getBody());
                throw new UnexpectedErrorException($decodedResponse);
                break;
        }
    }
468853
protected function checkResponse(Response $response)
    {
        $status = $response->getStatusCode();
        $reason = $response->getReasonPhrase();
        switch ($status) {
            case '403':
                throw new Exceptions\GeocodioAuthError($reason);
                break;

            case '422':
                throw new Exceptions\GeocodioDataError($reason);
                break;

            case '500':
                throw new Exceptions\GeocodioServerError($reason);
                break;

            case '200':
                return $response;
                break;

            default:
                throw new Exceptions\GeocodioException("There was a problem with your request - $reason");
                break;
        }
    }
1047826
private function checkResponse($response)
    {
        $hasRequestError = false;
        if (preg_match('/4\d\d/', $response->getStatusCode())) {
            $this->log('error', "Invalid API key or password");
            $this->addError(self::ERROR_HTTP_AUTHENTICATION_ERROR, false);
            $hasRequestError = true;
        } elseif (preg_match('/5\d\d/', $response->getStatusCode())) {
            $this->log('error', "Gateway error - HTTP " . $response->getStatusCode());
            $this->addError(self::ERROR_HTTP_SERVER_ERROR);
            $hasRequestError = true;
        } elseif ($response->getError()) {
            $this->log('error', "Connection error: " . $response->getError());
            $this->addError(self::ERROR_CONNECTION_ERROR);
            $hasRequestError = true;
        }

        if ($hasRequestError) {
            throw new RequestException(sprintf("Last HTTP response status code: %s", $response->getStatusCode()));
        }
    }
556449
private function setErrorFromResponse(Response $response)
    {
        $this->statusCode = $response->getStatus();
        $body = $response->getBody();
        if (isset($body['ErrorInfo'])) {
            $this->errorInfo = $body['ErrorInfo'];
        }
        if (isset($body['ErrorMessage'])) {
            $this->errorMessage = $body['ErrorMessage'];
        }
        if (isset($body['ErrorIdentifier'])) {
            $this->errorIdentifier = $body['ErrorIdentifier'];
        }
    }
847149
public function validateResponse($url, $response)
	{
		if (strpos($url, 'verify_credentials') === false && $response->code != 200)
		{
			$error = json_decode($response->body);

			if (property_exists($error, 'error'))
			{
				throw new \DomainException($error->error);
			}

			$error = $error->errors;

			throw new \DomainException($error[0]->message, $error[0]->code);
		}
	}
881220
public function execute($response) {

        $params = $this->parse_template();
        $tpid = $params['tool_proxy_id'];
        $bubble = optional_param('bubble', '', PARAM_ALPHA);
        $ok = !empty($tpid) && $this->check_tool_proxy($tpid, $response->get_request_data());
        if (!$ok) {
            $response->set_code(401);
        }
        $contenttype = $response->get_accept();
        $simpleformat = !empty($contenttype) && ($contenttype == $this->formats[1]);
        if ($ok) {
            $ok = (empty($bubble) || ((($bubble == 'distinct') || ($bubble == 'all')))) &&
               (!$simpleformat || empty($bubble) || ($bubble != 'all')) &&
               (empty($bubble) || ($response->get_request_method() == 'GET'));
            if (!$ok) {
                $response->set_code(406);
            }
        }

        if ($ok) {
            $systemsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id);
            if ($response->get_request_method() == 'GET') {
                $json = '';
                if ($simpleformat) {
                    $response->set_content_type($this->formats[1]);
                    $json .= "{";
                } else {
                    $response->set_content_type($this->formats[0]);
                    $json .= "{\n  \"@context\":\"http://purl.imsglobal.org/ctx/lti/v2/ToolSettings\",\n  \"@graph\":[\n";
                }
                $json .= toolsettings::settings_to_json($systemsettings, $simpleformat,
                    'ToolProxy', $this);
                if ($simpleformat) {
                    $json .= "\n}";
                } else {
                    $json .= "\n  ]\n}";
                }
                $response->set_body($json);
            } else { // PUT.
                $settings = null;
                if ($response->get_content_type() == $this->formats[0]) {
                    $json = json_decode($response->get_request_data());
                    $ok = !empty($json);
                    if ($ok) {
                        $ok = isset($json->{"@graph"}) && is_array($json->{"@graph"}) && (count($json->{"@graph"}) == 1) &&
                              ($json->{"@graph"}[0]->{"@type"} == 'ToolProxy');
                    }
                    if ($ok) {
                        $settings = $json->{"@graph"}[0]->custom;
                        unset($settings->{'@id'});
                    }
                } else {  // Simple JSON.
                    $json = json_decode($response->get_request_data(), true);
                    $ok = !empty($json);
                    if ($ok) {
                        $ok = is_array($json);
                    }
                    if ($ok) {
                        $settings = $json;
                    }
                }
                if ($ok) {
                    lti_set_tool_settings($settings, $this->get_service()->get_tool_proxy()->id);
                } else {
                    $response->set_code(406);
                }
            }
        }

    }
1311
function afterResponse(Swoole\Request $request, Swoole\Response $response)
    {
        if ($request->isWebSocket())
        {
            $conn = array('header' => $request->header, 'time' => time());
            $this->connections[$request->fd] = $conn;

            if (count($this->connections) > $this->max_connect)
            {
                $this->cleanConnection();
            }

            $this->onWsConnect($request->fd, $request);
        }
        parent::afterResponse($request, $response);
    }
1069472
private function handleResponse($response)
    {
        if ($this->client->newFormatModeEnabled === true) {
            return $response;
        }

        return $this->client->handleHttpResponse($response);
    }
67666
public function parseResponse($response)
    {
        // Parse the response and set the last response and headers.
        $info = curl_getinfo($this->ch);
        $this->__last_response_headers = substr(
            $response,
            0,
            $info['header_size']
        );
        $this->__last_response = substr($response, $info['header_size']);
    }
624578
public function emitResponse(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            $this->getResponseEmitter()->emit($response);
        } catch (\Exception $e) {
            if ($this->canForceResponseEmitting()) {
                // flush buffers
                $maxBufferLevel = ob_get_level();

                while (ob_get_level() > $maxBufferLevel) {
                    ob_end_flush();
                }

                // print response
                echo $response->getBody();
            } else {
                throw $e;
            }
        }
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_RESPONSE_SENT);
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $this->emit($applicationEvent);
    }
371128
private function setHttpResponse(OAuth2Response $response)
    {
        $httpResponse = $this->getResponse();
        $httpResponse->setStatusCode($response->getStatusCode());

        $headers = $httpResponse->getHeaders();
        $headers->addHeaders($response->getHttpHeaders());
        $headers->addHeaderLine('Content-type', 'application/json');

        $httpResponse->setContent($response->getResponseBody());
        return $httpResponse;
    }
212017
public function respond($response)
	{
		if (
			$this->logger !== null &&
			$this->logger->isHandling(Logger::DEBUG)
		) {
			$this->logger->addDebug(
				'Send response',
				array(
					 'content-type' => $this->contentType,
					 'response'     => ctype_print($response) ? $response : 'base64:' . base64_encode($response)
				)
			);
		}

		ob_start();
		while (ob_end_clean()) {
		}
		header('Content-Type: ' . $this->contentType);
		echo $response;
	}
1075749
public function setResponse(Response $response)
    {
        $this->response = $response;
        $this->context->registerInstance($response);
    }
983726
private function parseResponse($response) {
        $response = trim($response);
        $this->responseStatus = (int) substr($response, 0, 3);
        $this->response = substr($response, 4);
    }
878321
public function handleResponse(Request $request, Response $response)
    {
        if ($response->getStatusCode() == 422) {
            $errors = $response->getOriginalContent()['validation_errors'];

            throw new HttpResponseException(
                redirect()->back()->withInput($request->input())->withErrors($errors)
            );
        }

        if ($response->getStatusCode() == 403) {
            abort(403);
        }

        return $response->isNotFound() ? abort(404) : $response->getOriginalContent();
    }
1213167
private function loadResponse_v2($response) {
		// Set global Status-Values first
		if(isset($response->Status)) {
			if(isset($response->Status->statusCode))
				$this->setStatusCode((int) $response->Status->statusCode);
			if(isset($response->Status->statusText)) {
				if(is_array($response->Status->statusText))
					$this->setStatusText(implode(';', $response->Status->statusText));
				else
					$this->setStatusText($response->Status->statusText);
			}
			if(isset($response->Status->statusMessage)) {
				if(is_array($response->Status->statusMessage))
					$this->setStatusMessage(implode(';', $response->Status->statusMessage));
				else
					$this->setStatusMessage($response->Status->statusMessage);
			}
		}

		// Set Manifest if exists (getManifest)
		if(isset($response->manifestData)) {
			$this->setManifestData($response->manifestData);

			return;
		}

		/*
		 * Handle Shipment(s) | Calls on:
		 * 1 -> createShipmentOrder
		 * 2 -> deleteShipmentOrder
		 * 3 -> updateShipmentOrder [Only Single]
		 * 3 -> getLabel
		 * 4 -> validateShipment
		 * 5 -> getExportDoc
		 * 6 -> doManifest
		 */
		if(isset($response->CreationState)) // 1
			$this->handleMultiShipments($response->CreationState);
		else if(isset($response->DeletionState)) // 2
			$this->handleMultiShipments($response->DeletionState);
		else if(isset($response->LabelData)) // 3
			$this->handleMultiShipments($response->LabelData);
		else if(isset($response->ValidationState)) // 4
			$this->handleMultiShipments($response->ValidationState);
		else if(isset($response->ExportDocData)) // 5
			$this->handleMultiShipments($response->ExportDocData);
		else if(isset($response->ManifestState)) // 6
			$this->handleMultiShipments($response->ManifestState);

		// Validate the status to fix errors on the Main-Status and show weak-warnings
		if($this->getStatusCode() !== self::DHL_ERROR_NOT_SET)
			$this->validateStatusCode();
	}