This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new d7324942d fix(api): keep the backend message on a rejected blob export 
(#5928)
d7324942d is described below

commit d7324942d1c710e55766dd66ca70798659341252
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:18:52 2026 +0800

    fix(api): keep the backend message on a rejected blob export (#5928)
---
 web/src/api/client.test.ts | 34 ++++++++++++++++++++++++++++++++++
 web/src/api/client.ts      | 23 +++++++++++++++++++++--
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/web/src/api/client.test.ts b/web/src/api/client.test.ts
index 8b3c7d6b6..8ada68817 100644
--- a/web/src/api/client.test.ts
+++ b/web/src/api/client.test.ts
@@ -102,6 +102,40 @@ describe('API client response contract', () => {
     expect(message.error).toHaveBeenCalledWith('Topic name is required');
   });
 
+  it('extracts the backend message from a rejected blob export', async () => {
+    // The export endpoints answer a refusal with the same JSON envelope, but 
axios hands the body
+    // back as a Blob for a responseType: 'blob' request.
+    mock.onGet('/dlq/export-excel').reply(
+      501,
+      new Blob(
+        [
+          JSON.stringify({
+            code: 501,
+            message: 'DLQ operations are not supported for cloud instances',
+            data: null,
+          }),
+        ],
+        { type: 'application/json' },
+      ),
+    );
+
+    await expect(client.get('/dlq/export-excel', { responseType: 'blob' 
})).rejects.toThrow(
+      'DLQ operations are not supported for cloud instances',
+    );
+    expect(message.error).toHaveBeenCalledWith(
+      'DLQ operations are not supported for cloud instances',
+    );
+  });
+
+  it('keeps the transport error when a rejected blob carries no envelope', 
async () => {
+    mock.onGet('/dlq/export-excel').reply(502, new Blob(['<html>bad 
gateway</html>']));
+
+    await expect(client.get('/dlq/export-excel', { responseType: 'blob' 
})).rejects.toThrow(
+      'Request failed with status code 502',
+    );
+    expect(message.error).not.toHaveBeenCalled();
+  });
+
   it('uses a stable fallback for malformed error envelopes', async () => {
     mock.onGet('/clusters').reply(200, { code: '500', data: null });
 
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 77604949c..80e67278c 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -32,6 +32,23 @@ function isBusinessResponse(data: unknown): data is 
BusinessResponse {
   return typeof data === 'object' && data !== null;
 }
 
+/**
+ * A `responseType: 'blob'` request hands its error body back as a Blob, so 
the envelope is opaque
+ * to {@link getBusinessError}. The export endpoints answer their refusals 
with the same JSON
+ * envelope as everything else (e.g. "Audit log export exceeds the maximum of 
10000 records"), and
+ * without this the caller surfaces axios's transport text instead.
+ */
+async function getBusinessErrorFromBlob(data: unknown): Promise<string | null> 
{
+  if (typeof Blob === 'undefined' || !(data instanceof Blob)) {
+    return null;
+  }
+  try {
+    return getBusinessError(JSON.parse(await data.text()));
+  } catch {
+    return null;
+  }
+}
+
 function getBusinessError(data: unknown): string | null {
   if (!isBusinessResponse(data) || data.code === undefined) {
     return null;
@@ -116,7 +133,7 @@ client.interceptors.response.use(
     }
     return response;
   },
-  (error) => {
+  async (error) => {
     if (error.response?.status === 401 && 
!isPublicAuthRequest(error.config?.url)) {
       const requestEpoch = (error.config as { sessionEpoch?: number } | 
undefined)?.sessionEpoch;
       handleSessionUnauthorized(requestEpoch);
@@ -129,7 +146,9 @@ client.interceptors.response.use(
       }
       return Promise.reject(error);
     }
-    const errorMessage = getBusinessError(error.response?.data);
+    const errorMessage =
+      getBusinessError(error.response?.data) ??
+      (await getBusinessErrorFromBlob(error.response?.data));
     if (errorMessage) {
       message.error(errorMessage);
       if (error instanceof Error) {

Reply via email to