From 185f55cec68a7d2c90620e70fc352ed26585a118 Mon Sep 17 00:00:00 2001 From: wren <“porlong@qq.com”> Date: Thu, 30 Apr 2026 11:47:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pass=20through=20server=20403=20message?= =?UTF-8?q?=20instead=20of=20hardcoded=20'=E6=97=A0=E6=9D=83=E9=99=90'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The axios response interceptor was discarding the server's permission-denied message (e.g. "缺少「用户列表」权限") and replacing it with a generic "无权限". Now it reads the server response body and surfaces the exact permission that's missing. --- app/api/axios-client.ts | 6 ++---- app/routes/role-permissions._index.tsx | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/api/axios-client.ts b/app/api/axios-client.ts index c917180..69422bf 100644 --- a/app/api/axios-client.ts +++ b/app/api/axios-client.ts @@ -183,10 +183,8 @@ axiosInstance.interceptors.response.use( // 🔒 403 无权限错误处理 if (isAxiosError(error) && error.response?.status === 403) { console.warn('⚠️ [403 Forbidden] 无权限访问:', error.config?.url); - - // 修改错误消息为友好提示,避免显示原始的 "Request failed with status code 403" - // 注意:不在这里显示 toast,由组件层统一处理,避免重复提示 - error.message = '无权限'; + const serverMessage = (error.response?.data as any)?.message; + error.message = serverMessage || '无权限'; } return Promise.reject(error); diff --git a/app/routes/role-permissions._index.tsx b/app/routes/role-permissions._index.tsx index d103f49..032cfbc 100644 --- a/app/routes/role-permissions._index.tsx +++ b/app/routes/role-permissions._index.tsx @@ -1194,8 +1194,9 @@ export default function RolePermissions() { setExpandedRouteIds([]); // 重置展开状态 setRoleUsers(users); } catch (error) { + const errMsg = error instanceof Error ? error.message : '加载角色权限失败'; console.error('加载角色权限失败:', error); - toastService.error('加载角色权限失败'); + toastService.error(errMsg); } finally { setLoadingPermissions(false); // v3.8: 结束加载权限 setLoadingUsers(false); // 结束加载用户列表