static function display ($exception, ResponseInterface $response = null)
  {
    // For HTML pages, output the error popup

    if (strpos (get ($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
      ob_start ();
      ErrorConsoleRenderer::renderStyles ();
      $stackTrace = self::getStackTrace ($exception->getPrevious () ?: $exception);
      ErrorConsoleRenderer::renderPopup ($exception, self::$appName, $stackTrace);
      $popup = ob_get_clean ();

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($popup);
        return $response->withStatus (500);
      }

      // Direct output

      echo $popup;
    }

    // For other content types, output a plain text message, replacing any existing response content
    else {

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($exception->getMessage ());
        if (self::$devEnv)
          $response->getBody ()->write ("\n\nStack trace:\n" . $exception->getTraceAsString ());
        return $response
          ->withoutHeader ('Content-Type')
          ->withHeader ('Content-Type', 'text-plain')
          ->withStatus (500);
      }

      // Direct output

      header ("Content-Type: text/plain");
      http_response_code (500);
      echo $exception->getMessage ();
      if (self::$devEnv)
        echo "\n\nStack trace:\n" . $exception->getTraceAsString ();
    }
    return null;
  }