Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Clarify publish timeout errors (#6406)

Oleg Isonenaa1587c100fc
diff --git a/apps/builder/app/builder/features/publish/publish-error.test.ts b/apps/builder/app/builder/features/publish/publish-error.test.ts
new file mode 100644
index 0000000000..9e435a8e16
--- /dev/null
+++ b/apps/builder/app/builder/features/publish/publish-error.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, test } from "vitest";
+import { TRPCClientError } from "@trpc/client";
+import {
+ getPrePublishErrorMessage,
+ prePublishTimeoutMessage,
+} from "./publish-error";
+
+describe("getPrePublishErrorMessage", () => {
+ test("describes a gateway timeout in terms of the publish flow", () => {
+ const response = new Response("<!DOCTYPE html>", {
+ status: 504,
+ headers: { "content-type": "text/html" },
+ });
+ const error = TRPCClientError.from(
+ new SyntaxError("Unexpected token '<'"),
+ { meta: { response } }
+ );
+
+ expect(getPrePublishErrorMessage(error)).toBe(prePublishTimeoutMessage);
+ });
+
+ test("recognizes the Vercel timeout code", () => {
+ const response = new Response("Timed out", {
+ status: 500,
+ headers: { "x-vercel-error": "FUNCTION_INVOCATION_TIMEOUT" },
+ });
+ const error = TRPCClientError.from(new SyntaxError("Unexpected token"), {
+ meta: {
+ response,
+ },
+ });
+
+ expect(getPrePublishErrorMessage(error)).toBe(prePublishTimeoutMessage);
+ });
+});
diff --git a/apps/builder/app/builder/features/publish/publish-error.ts b/apps/builder/app/builder/features/publish/publish-error.ts
new file mode 100644
index 0000000000..4849df780b
--- /dev/null
+++ b/apps/builder/app/builder/features/publish/publish-error.ts
@@ -0,0 +1,21 @@
+import { TRPCClientError } from "@trpc/client";
+
+export const prePublishTimeoutMessage =
+ "Pre-publish checks timed out. Publishing was not started. Please try again.";
+
+export const getPrePublishErrorMessage = (error: unknown) => {
+ const response =
+ error instanceof TRPCClientError && error.meta?.response instanceof Response
+ ? error.meta.response
+ : undefined;
+ if (
+ response !== undefined &&
+ (response.status === 504 ||
+ response.headers.get("x-vercel-error") === "FUNCTION_INVOCATION_TIMEOUT")
+ ) {
+ return prePublishTimeoutMessage;
+ }
+ return error instanceof Error
+ ? error.message
+ : "Content database validation failed";
+};
diff --git a/apps/builder/app/builder/features/publish/publish.tsx b/apps/builder/app/builder/features/publish/publish.tsx
index 4014954323..1fe93a421a 100644
--- a/apps/builder/app/builder/features/publish/publish.tsx
+++ b/apps/builder/app/builder/features/publish/publish.tsx
@@ -105,6 +105,7 @@ import {
import { showContentDatabasePublishWarning } from "./content-database-publish-warning";
import { showPublishWarning } from "./publish-warning";
import { flushExternalContentProject } from "~/shared/external-content-roots";
+import { getPrePublishErrorMessage } from "./publish-error";
const PrePublishAuditMessage = ({
finding,
@@ -658,10 +659,7 @@ const Publish = ({
setWarning: setPublishWarning,
});
} catch (error) {
- const message =
- error instanceof Error
- ? error.message
- : "Content database validation failed";
+ const message = getPrePublishErrorMessage(error);
toast.error(message);
setPublishError(message);
return;