Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Show plain-text 4xx body in guest embed visualization (#73646)

Sébastienf1b2f28b3ab6
diff --git a/frontend/src/metabase/services.js b/frontend/src/metabase/services.js
index 3108e59f477..0de776daa77 100644
--- a/frontend/src/metabase/services.js
+++ b/frontend/src/metabase/services.js
@@ -51,6 +51,13 @@ async function handleQueryApiError(apiPromise) {
error.status < 500 &&
error.data
) {
+ // The QP returns a structured `{ error, error_type, ... }` body, but
+ // plainer endpoints (e.g. `/api/embed/*` API-level checks) return a
+ // plain-text body. Normalize so callers can rely on a `{ error, ... }`
+ // shape and don't fall through to the empty state (EMB-1659).
+ if (typeof error.data === "string") {
+ return { error: error.data, status: error.status };
+ }
return error.data;
}
// For 5xx and other errors, re-throw
diff --git a/frontend/src/metabase/services.unit.spec.ts b/frontend/src/metabase/services.unit.spec.ts
index 07af12b3291..3165ca8d85c 100644
--- a/frontend/src/metabase/services.unit.spec.ts
+++ b/frontend/src/metabase/services.unit.spec.ts
@@ -259,5 +259,26 @@ describe("metabase/services > runQuestionQuery", () => {
status: 500,
});
});
+
+ it("normalizes plain-text 4xx error bodies into a structured error result (EMB-1659)", async () => {
+ // Embed API checks (e.g. `/api/embed/card/:token/query`) reject with a
+ // plain-text body when a locked param is missing from the JWT. Without
+ // normalization the result reaches the visualization as a bare string,
+ // so `result?.error` is undefined and the UI falls through to an empty
+ // state instead of showing the message.
+ const question = createMockSavedQuestion();
+ const errorMessage = "You must specify a value for category in the JWT.";
+
+ fetchMock.post(getQueryEndpointPath(question), {
+ status: 400,
+ body: errorMessage,
+ });
+
+ const result = await runQuestionQuery(question, {
+ cancelDeferred: defer(),
+ });
+
+ expect(result).toEqual([{ error: errorMessage, status: 400 }]);
+ });
});
});