public function handleError(
        $exception,
        ServerRequestInterface $request,
        ResponseInterface $response,
        $catch = self::DEFAULT_ERROR_CATCH
    )
    {
        // notify app that an error occurs
        $this->error = true;

        $errorHandler = $this->getErrorHandler();

        // if delivered value of $catch, then configured value, then default value
        $catch = self::DEFAULT_ERROR_CATCH !== $catch ? $catch : $this->getConfig(self::KEY_ERROR_CATCH, $catch);

        $showError = $this->getConfig(self::KEY_ERROR, static::DEFAULT_ERROR);

        $this->pushException($errorHandler->decorateException($exception));

        //execute application middlewares
        try {
            $middlewares = $this->getRouter()->getMiddlewareStack();
            $middlewareRunner = new ExecutionChain();
            foreach ($middlewares as $middleware) {
                $middlewareRunner->middleware($middleware);
            }

            $response = $middlewareRunner->execute($request, $response);
        }catch (\Exception $e){
            $this->pushException($e);
        }

        // get last occured exception
        $exception = $this->getLastException();

        $message = $errorHandler->getErrorMessage($exception);

        $errorResponse = $this->determineErrorResponse($exception, $message, $response, $request);

        if (
            false === $catch
            && true === $showError
        ) {
            $this->throwException($exception);
        }

        return $errorResponse;
    }
public function handleError(
        $exception,
        ServerRequestInterface $request,
        ResponseInterface $response,
        $catch = self::DEFAULT_ERROR_CATCH
    )
    {
        // notify app that an error occurs
        $this->error = true;

        $errorHandler = $this->getErrorHandler();

        // if delivered value of $catch, then configured value, then default value
        $catch = self::DEFAULT_ERROR_CATCH !== $catch ? $catch : $this->getConfig(self::KEY_ERROR_CATCH, $catch);

        $showError = $this->getConfig(self::KEY_ERROR, static::DEFAULT_ERROR);

        $this->pushException($errorHandler->decorateException($exception));

        //execute application middlewares
        try {
            $middlewares = $this->getRouter()->getMiddlewareStack();
            $middlewareRunner = new ExecutionChain();
            foreach ($middlewares as $middleware) {
                $middlewareRunner->middleware($middleware);
            }

            $response = $middlewareRunner->execute($request, $response);
        }catch (\Exception $e){
            $this->pushException($e);
        }

        // get last occured exception
        $exception = $this->getLastException();

        $message = $errorHandler->getErrorMessage($exception);

        $errorResponse = $this->determineErrorResponse($exception, $message, $response, $request);

        if (
            false === $catch
            && true === $showError
        ) {
            $this->throwException($exception);
        }

        return $errorResponse;
    }
public function handleError ( $ exception , ServerRequestInterface $ request , ResponseInterface $ response , $ catch = self :: DEFAULT_ERROR_CATCH ) { // notify app that an error occurs $ this -> error = true ; $ errorHandler = $ this -> getErrorHandler ( ) ; // if delivered value of $catch, then configured value, then default value $ catch = self :: DEFAULT_ERROR_CATCH !== $ catch ? $ catch : $ this -> getConfig ( self :: KEY_ERROR_CATCH , $ catch ) ; $ showError = $ this -> getConfig ( self :: KEY_ERROR , static :: DEFAULT_ERROR ) ; $ this -> pushException ( $ errorHandler -> decorateException ( $ exception ) ) ; //execute application middlewares try { $ middlewares = $ this -> getRouter ( ) -> getMiddlewareStack ( ) ; $ middlewareRunner = new ExecutionChain ( ) ; foreach ( $ middlewares as $ middleware ) { $ middlewareRunner -> middleware ( $ middleware ) ; } $ response = $ middlewareRunner -> execute ( $ request , $ response ) ; } catch ( \ Exception $ e ) { $ this -> pushException ( $ e ) ; } // get last occured exception $ exception = $ this -> getLastException ( ) ; $ message = $ errorHandler -> getErrorMessage ( $ exception ) ; $ errorResponse = $ this -> determineErrorResponse ( $ exception , $ message , $ response , $ request ) ; if ( false === $ catch && true === $ showError ) { $ this -> throwException ( $ exception ) ; } return $ errorResponse ; }
Handle error and return response of error message or throw
error if error.catch is disabled.

@param \Throwable|\Exception $exception
@param \Psr\Http\Message\ServerRequestInterface $request
@param ResponseInterface $response
@param bool $catch

@return \Psr\Http\Message\ResponseInterface

@throws string
Handle error and return response of error message or throw error if error . catch is disabled .