private function determineErrorResponse(
        $exception,
        $message,
        ResponseInterface $response,
        ServerRequestInterface $request
    )
    {
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_LIFECYCLE_ERROR);
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $applicationEvent->setErrorResponse($this->getResponse());

        $this->emit($applicationEvent, $exception);

        $errorResponse = $applicationEvent->getErrorResponse();

        if (!$errorResponse->getBody()->isWritable()) {
            return $errorResponse;
        }

        $content = $errorResponse->getBody()->__toString();
        if (empty($content)) {
            $errorResponse->getBody()->write($message);
        }

        return $errorResponse;
    }
private function determineErrorResponse(
        $exception,
        $message,
        ResponseInterface $response,
        ServerRequestInterface $request
    )
    {
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_LIFECYCLE_ERROR);
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $applicationEvent->setErrorResponse($this->getResponse());

        $this->emit($applicationEvent, $exception);

        $errorResponse = $applicationEvent->getErrorResponse();

        if (!$errorResponse->getBody()->isWritable()) {
            return $errorResponse;
        }

        $content = $errorResponse->getBody()->__toString();
        if (empty($content)) {
            $errorResponse->getBody()->write($message);
        }

        return $errorResponse;
    }
private function determineErrorResponse ( $ exception , $ message , ResponseInterface $ response , ServerRequestInterface $ request ) { $ applicationEvent = $ this -> getApplicationEvent ( ) ; $ applicationEvent -> setName ( self :: EVENT_LIFECYCLE_ERROR ) ; $ applicationEvent -> setRequest ( $ request ) ; $ applicationEvent -> setResponse ( $ response ) ; $ applicationEvent -> setErrorResponse ( $ this -> getResponse ( ) ) ; $ this -> emit ( $ applicationEvent , $ exception ) ; $ errorResponse = $ applicationEvent -> getErrorResponse ( ) ; if ( ! $ errorResponse -> getBody ( ) -> isWritable ( ) ) { return $ errorResponse ; } $ content = $ errorResponse -> getBody ( ) -> __toString ( ) ; if ( empty ( $ content ) ) { $ errorResponse -> getBody ( ) -> write ( $ message ) ; } return $ errorResponse ; }
Determines response for error. Emits `lifecycle.error` event.

@param \Throwable $exception
@param string $message
@param ResponseInterface $response
@param ServerRequestInterface $request
@return ResponseInterface
Determines response for error . Emits lifecycle . error event .