You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2026/08/14 07:39:07 UTC
(hugegraph-toolchain) 05/20: fix(hubble): sanitize request failure feedback
This is an automated email from the ASF dual-hosted git repository.
imbajin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph-toolchain.git
commit 58c480388eb1414c462f2e8864c6dbcd04bdc5e1
Author: dark <ji...@apache.org>
AuthorDate: Fri Aug 14 12:39:02 2026 +0800
fix(hubble): sanitize request failure feedback
---
.../src/api/request-error-semantics.test.js | 41 +++++++++++++++++++++-
hugegraph-hubble/hubble-fe/src/api/request.js | 13 +++++--
.../i18n/resources/en-US/components/common.json | 3 +-
3 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/hugegraph-hubble/hubble-fe/src/api/request-error-semantics.test.js b/hugegraph-hubble/hubble-fe/src/api/request-error-semantics.test.js
index 5acd878fc..b539b7f42 100644
--- a/hugegraph-hubble/hubble-fe/src/api/request-error-semantics.test.js
+++ b/hugegraph-hubble/hubble-fe/src/api/request-error-semantics.test.js
@@ -106,7 +106,7 @@ describe.each(['./request'])('%s error semantics', modulePath => {
};
expect(reject(error)).toBe(error.response);
- expect(messageError).toHaveBeenCalledWith('request.error');
+ expect(messageError).toHaveBeenCalledWith('request.error_with_path');
});
it('keeps network errors rejected after showing the fallback message', async () => {
@@ -114,7 +114,46 @@ describe.each(['./request'])('%s error semantics', modulePath => {
const error = new Error('Network Error');
await expect(reject(error)).rejects.toBe(error);
+ expect(messageError).toHaveBeenCalledWith('request.failed');
+ });
+
+ it('keeps fallback and detailed copy from repeating the failure prefix',
+ () => {
+ const en = require('../i18n/resources/en-US/components/common.json');
+ const zh = require('../i18n/resources/zh-CN/components/common.json');
+ const interpolate = (template, values) => Object.entries(values)
+ .reduce((text, [key, value]) => text.replace(
+ `{{${key}}}`,
+ value
+ ), template);
+
+ expect(en.request.failed).toBe('Request failed');
+ expect(interpolate(en.request.error, {
+ message: 'Connection unavailable',
+ })).toBe('Request failed: Connection unavailable');
+ expect(zh.request.failed).toBe('请求失败');
+ expect(interpolate(zh.request.error, {
+ message: '暂时无法连接',
+ })).toBe('请求失败:暂时无法连接');
+ });
+
+ it('omits the path label when the server does not provide a path', () => {
+ const {reject, messageError} = loadResponseHandlers(modulePath);
+ const error = {
+ config: {},
+ response: {
+ status: 500,
+ data: {
+ status: 500,
+ message: 'No service available',
+ path: ' ',
+ },
+ },
+ };
+
+ expect(reject(error)).toBe(error.response);
expect(messageError).toHaveBeenCalledWith('request.error');
+ expect(messageError).not.toHaveBeenCalledWith('request.error_with_path');
});
it('redacts secrets and absolute paths before errors reach the DOM', async () => {
diff --git a/hugegraph-hubble/hubble-fe/src/api/request.js b/hugegraph-hubble/hubble-fe/src/api/request.js
index 84a534b6a..3f3432e1d 100644
--- a/hugegraph-hubble/hubble-fe/src/api/request.js
+++ b/hugegraph-hubble/hubble-fe/src/api/request.js
@@ -50,9 +50,16 @@ const redirectToLogin = () => {
};
const showRequestError = res => {
- message.error(i18n.t('request.error', {
- message: res?.message ?? '',
- path: res?.path ?? '',
+ const errorMessage = res?.message;
+ if (!errorMessage) {
+ message.error(i18n.t('request.failed'));
+ return;
+ }
+ const path = typeof res?.path === 'string' ? res.path.trim() : '';
+ const key = path ? 'request.error_with_path' : 'request.error';
+ message.error(i18n.t(key, {
+ message: errorMessage,
+ path,
}));
};
diff --git a/hugegraph-hubble/hubble-fe/src/i18n/resources/en-US/components/common.json b/hugegraph-hubble/hubble-fe/src/i18n/resources/en-US/components/common.json
index d48db0e7a..fa17a2657 100644
--- a/hugegraph-hubble/hubble-fe/src/i18n/resources/en-US/components/common.json
+++ b/hugegraph-hubble/hubble-fe/src/i18n/resources/en-US/components/common.json
@@ -98,6 +98,7 @@
},
"request": {
"failed": "Request failed",
- "error": "Request failed: {{message}}, path: {{path}}"
+ "error": "Request failed: {{message}}",
+ "error_with_path": "Request failed: {{message}} ({{path}})"
}
}