This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 7fa944bd3 fix(web): preserve REST API error messages (#1975)
7fa944bd3 is described below
commit 7fa944bd3492fe754f74c117c0f14a71985d3757
Author: coder999o <[email protected]>
AuthorDate: Wed Aug 19 11:50:29 2026 +0800
fix(web): preserve REST API error messages (#1975)
---
web/src/api/client.test.ts | 12 ++++++++++++
web/src/api/client.ts | 8 ++++++++
2 files changed, 20 insertions(+)
diff --git a/web/src/api/client.test.ts b/web/src/api/client.test.ts
index 4739a3c07..2aecc767b 100644
--- a/web/src/api/client.test.ts
+++ b/web/src/api/client.test.ts
@@ -90,6 +90,17 @@ describe('API client response contract', () => {
expect(message.error).toHaveBeenCalledWith('Topic already exists');
});
+ it('rejects failed HTTP envelopes with the backend message', async () => {
+ mock.onPost('/topics/create').reply(400, {
+ code: 400,
+ message: 'Topic name is required',
+ data: null,
+ });
+
+ await expect(client.post('/topics/create', {})).rejects.toThrow('Topic
name is required');
+ expect(message.error).toHaveBeenCalledWith('Topic name is required');
+ });
+
it('uses a stable fallback for malformed error envelopes', async () => {
mock.onGet('/clusters').reply(200, { code: '500', data: null });
@@ -144,6 +155,7 @@ describe('API client response contract', () => {
expect(localStorage.getItem('rocketmq-studio-user')).toBeNull();
expect(localStorage.getItem('rocketmq-studio-user-admin')).toBeNull();
+ expect(message.error).not.toHaveBeenCalled();
});
it('preserves the original 401 error when the request URL is malformed',
async () => {
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index a8b025f8d..4fe9f5e53 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -81,6 +81,14 @@ client.interceptors.response.use(
clearAiChatHistories();
clearAuthSession();
window.location.href = '/';
+ return Promise.reject(error);
+ }
+ const errorMessage = getBusinessError(error.response?.data);
+ if (errorMessage) {
+ message.error(errorMessage);
+ if (error instanceof Error) {
+ error.message = errorMessage;
+ }
}
return Promise.reject(error);
},