private function handleError(RequestInterface $request, ResponseInterface $response, \Throwable $throwable = null): void
    {
        $errorControllerClass = $this->getErrorControllerClass();

        if ($errorControllerClass !== null) {
            /** @var ErrorControllerInterface $errorController */
            $errorController = new $errorControllerClass();
            if ($throwable !== null) {
                $errorController->setThrowable($throwable);
            }

            try {
                $errorController->processRequest($this, $request, $response, strval($response->getStatusCode()->getCode()), []);
            } catch (\Throwable $throwable) {
                $this->throwableToResponse($throwable, $response);
            }
        }
    }