protected function generateOutputHandler(
        ServerRequestInterface $request,
        ResponseInterface $response,
        \Throwable $e
    ) : ResponseInterface {

        $contentType = $this->getContentType();
        // if content type has not been set
        // get it from Request / Response
        if (!$contentType) {
            $contentType = $response->getHeaderLine('Content-Type')?: (
                $request->getHeaderLine('Content-Type')?: static::DEFAULT_CONTENT_TYPE
            );
            $this->setContentType($contentType);
        }

        $this->cleanOutputBuffer();
        $body = new RequestBody();

        $handler = $this->getOutputHandler($request, $response, $e);
        // disable quit
        $handler->allowQuit(false);
        // log
        $this->logThrowable($e);
        // write handler
        $body->write($handler->handleException($e));

        return $response->withBody($body)->withHeader('Content-Type', $contentType);
    }