fix(datasource): improve error handling and user feedback in DataSource components

- Updated error handling in DataSourceSettings and DataSourceEditorDialog to provide more informative messages.
- Enhanced the UI to display error details more clearly, improving user experience during connection tests and resource loading.
- Adjusted HTTP response status checks in request utility for better accuracy in handling success responses.
This commit is contained in:
wizardchen
2026-03-30 15:08:57 +08:00
committed by lyingbug
parent 8021647929
commit 36dac0120a
4 changed files with 82 additions and 24 deletions
+13 -4
View File
@@ -82,7 +82,7 @@ instance.interceptors.response.use(
(response) => {
// 根据业务状态码处理逻辑
const { status, data } = response;
if (status === 200 || status === 201) {
if (status >= 200 && status < 300) {
return data;
} else {
return Promise.reject(data);
@@ -190,9 +190,18 @@ instance.interceptors.response.use(
// 将HTTP状态码一并抛出,方便上层判断401等场景
// 后端返回格式: { success: false, error: { code, message, details } }
// 提取 error.message 作为顶层 message,方便前端使用 error?.message 获取
const errorMessage = typeof data === 'object' && data?.error?.message
? data.error.message
: (typeof data === 'object' ? data?.message : data);
let errorMessage: string | undefined;
if (typeof data === 'object') {
if (typeof data?.error === 'string') {
errorMessage = data.error;
} else if (data?.error?.message) {
errorMessage = data.error.message;
} else {
errorMessage = data?.message;
}
} else if (typeof data === 'string') {
errorMessage = data;
}
return Promise.reject({
status,
message: errorMessage,