The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix /api/frontend-errors 404 in embedded contexts (#74623)
Sébastien758bd2579bdb
diff --git a/frontend/src/metabase/embedding/lib/override-requests-for-embeds.ts b/frontend/src/metabase/embedding/lib/override-requests-for-embeds.tsindex c74bee624f5..4245f62ddba 100644--- a/frontend/src/metabase/embedding/lib/override-requests-for-embeds.ts+++ b/frontend/src/metabase/embedding/lib/override-requests-for-embeds.ts@@ -20,6 +20,9 @@ const getBaseUrlByEmbedType = (embedType: EmbedType): string =>const getIgnoreOverridePatterns = () => [sessionPropertiesPath,PLUGIN_CONTENT_TRANSLATION.getDictionaryBasePath,+ // `/api/frontend-errors` only exists at the canonical path (see+ // metabase.frontend-errors.api) — rewriting it would 404.+ "/api/frontend-errors",];/**@@ -182,7 +185,7 @@ function replaceWithEmbedBase({return url;}-const overrideRequests = async ({+export const overrideRequests = async ({embedType,method,url,diff --git a/frontend/src/metabase/embedding/lib/override-requests-for-embeds.unit.spec.ts b/frontend/src/metabase/embedding/lib/override-requests-for-embeds.unit.spec.tsindex fea63742cfd..9fda0646524 100644--- a/frontend/src/metabase/embedding/lib/override-requests-for-embeds.unit.spec.ts+++ b/frontend/src/metabase/embedding/lib/override-requests-for-embeds.unit.spec.ts@@ -1,4 +1,7 @@-import { matchUrlPattern } from "./override-requests-for-embeds";+import {+ matchUrlPattern,+ overrideRequests,+} from "./override-requests-for-embeds";describe("matchUrlPattern", () => {it("should match URL with single parameter", () => {@@ -91,3 +94,48 @@ describe("matchUrlPattern", () => {).toBe(true);});});++describe("overrideRequests", () => {+ const defaultOptions = { hasBody: false };++ it.each(["guest", "static", "public"] as const)(+ "leaves /api/frontend-errors untouched in %s embed mode",+ async (embedType) => {+ const result = await overrideRequests({+ embedType,+ method: "POST",+ url: "/api/frontend-errors",+ options: { ...defaultOptions, hasBody: true },+ data: { type: "component-crash" },+ });++ expect(result.url).toBe("/api/frontend-errors");+ expect(result.method).toBe("POST");+ },+ );++ it("still applies the default /api → /api/embed rewrite to passthrough endpoints", async () => {+ const result = await overrideRequests({+ embedType: "guest",+ method: "GET",+ url: "/api/card/THE_JWT_TOKEN",+ options: defaultOptions,+ data: {},+ });++ expect(result.url).toBe("/api/embed/card/THE_JWT_TOKEN");+ });++ it("still applies explicit transformations (card query → embed card query)", async () => {+ const result = await overrideRequests({+ embedType: "guest",+ method: "POST",+ url: "/api/card/123/query",+ options: { ...defaultOptions, hasBody: true },+ data: {},+ });++ expect(result.url).toBe("/api/embed/card/:token/query");+ expect(result.method).toBe("GET");+ });+});