Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.4 KB
Raw Blame
import { isAxiosError } from "axios";
import { extractAxiosErrorMessage } from "@editor/services/httpErrorUtils";
import { alert } from "@editor/components/toast";
import i18n from "i18next";

/**
 * Desktop implementation: intercepts errors from SaaS backend requests
 * and shows a specific "Cloud Processing Failed" alert.
 *
 * _isSaaSRequest is set by the desktop apiClientSetup interceptor when
 * a request is routed to the SaaS backend instead of the local backend.
 *
 * Returns true if the error was handled (suppresses further processing),
 * false if this is not a SaaS error.
 */
export function handleSaaSError(error: unknown): boolean {
  if (
    !isAxiosError(error) ||
    (error.config as { _isSaaSRequest?: boolean })?._isSaaSRequest !== true
  )
    return false;

  const { title: originalTitle, body: originalBody } =
    extractAxiosErrorMessage(error);

  alert({
    alertType: "error",
    title: i18n.t("desktop.saasError.title", "Cloud Processing Failed"),
    body: i18n.t(
      "desktop.saasError.body",
      "This tool requires cloud processing but encountered an error: {{error}}. Please check your connection and try again.",
      { error: originalBody },
    ),
    expandable: true,
    isPersistentPopup: false,
  });

  console.error("[saasErrorInterceptor] SaaS backend error:", {
    originalTitle,
    originalBody,
  });
  return true;
}