public function handleRequest(ServerRequestInterface $serverRequest, ResponseInterface $response): ResponseInterface
    {
        $response = $response->withProtocolVersion($serverRequest->getProtocolVersion());

        try {
            try {
                $APIRequest = $this->requestFactory->create($serverRequest);
            } catch (UnableToCreateRequestException $exception) {
                return $this->handleRequestFactoryException($exception, $response);
            }

            try {
                $APIResponse = $this->server->handleRequest($APIRequest);
            } catch (UnableToHandleRequestException $exception) {
                return $this->handleServerException($exception, $response);
            }

            return $this->buildResponse($APIResponse, $response);
        } catch (\Throwable $e) {
            $this->logCaughtThrowableResultingInHTTPCode(500, $e, LogLevel::CRITICAL);
            return $response->withStatus(500, "Internal Server Error");
        }
    }
public function handleRequest(ServerRequestInterface $serverRequest, ResponseInterface $response): ResponseInterface
    {
        $response = $response->withProtocolVersion($serverRequest->getProtocolVersion());

        try {
            try {
                $APIRequest = $this->requestFactory->create($serverRequest);
            } catch (UnableToCreateRequestException $exception) {
                return $this->handleRequestFactoryException($exception, $response);
            }

            try {
                $APIResponse = $this->server->handleRequest($APIRequest);
            } catch (UnableToHandleRequestException $exception) {
                return $this->handleServerException($exception, $response);
            }

            return $this->buildResponse($APIResponse, $response);
        } catch (\Throwable $e) {
            $this->logCaughtThrowableResultingInHTTPCode(500, $e, LogLevel::CRITICAL);
            return $response->withStatus(500, "Internal Server Error");
        }
    }
public function handleRequest ( ServerRequestInterface $ serverRequest , ResponseInterface $ response ) : ResponseInterface { $ response = $ response -> withProtocolVersion ( $ serverRequest -> getProtocolVersion ( ) ) ; try { try { $ APIRequest = $ this -> requestFactory -> create ( $ serverRequest ) ; } catch ( UnableToCreateRequestException $ exception ) { return $ this -> handleRequestFactoryException ( $ exception , $ response ) ; } try { $ APIResponse = $ this -> server -> handleRequest ( $ APIRequest ) ; } catch ( UnableToHandleRequestException $ exception ) { return $ this -> handleServerException ( $ exception , $ response ) ; } return $ this -> buildResponse ( $ APIResponse , $ response ) ; } catch ( \ Throwable $ e ) { $ this -> logCaughtThrowableResultingInHTTPCode ( 500 , $ e , LogLevel :: CRITICAL ) ; return $ response -> withStatus ( 500 , "Internal Server Error" ) ; } }
Clones a response, changing contents based on the handling of a given request.
Taking in a response allows us not to define a specific response implementation to create.
@param ServerRequestInterface $serverRequest
@param ResponseInterface $response
@return ResponseInterface
Clones a response changing contents based on the handling of a given request . Taking in a response allows us not to define a specific response implementation to create .