🐛 导入失败时显示后端业务提示,不再误报系统错误

问题(用户实测反馈):导入只有一个表头的空文件时,前端提示「系统错误」,
用户误以为系统崩溃;后端其实已返回明确文案(400 + 「导入数据不能为空」)。

根因(两处叠加):
1) axios 错误分支 reject(new Error(error)) 把原始错误包装掉,
   error.response 丢失、message 退化成 [object Object];
2) 导入接口统一用 responseType:'blob',非 2xx 的响应体也是 Blob,
   而 axios 错误分支不做解析,拿不到后端 msg。

修复:
- src/axios.js:错误分支直接 reject 原始 axios 错误,保留 response;
- src/utils/import-excel.js:新增 resolveErrorMessage,从错误响应的 Blob 中
  解析后端 JSON 取 msg;解析不到时兜底为中文提示(不再暴露
  「Request failed with status code xxx」这类英文技术文案)。

验证:vite build 通过;模拟真实响应体验证 400 + 空表场景,
提示由「系统错误」变为后端原文「未读取到数据行,请确认表头下方已填写内容」。
This commit is contained in:
2026-09-26 11:50:49 +08:00
parent 815810f841
commit 088c9cace0
2 changed files with 33 additions and 2 deletions
+4 -1
View File
@@ -223,7 +223,10 @@ axios.interceptors.response.use(
},
error => {
NProgress.done();
return Promise.reject(new Error(error));
// 保留原始 axios 错误对象:下游(如导入失败明细解析)需要 error.response
// 读取响应体。若包装成 new Error(error),response 会丢失、message 退化成
// "[object Object]",用户只能看到无意义的通用提示。
return Promise.reject(error);
}
);