feat: 添加 403 无权限弹窗提示
## 修改内容 在 axios 响应拦截器中添加 403 Forbidden 错误处理: - 检测到 403 状态码时,显示 toast 警告提示 - 提示信息:"无权限访问该资源" - 只在客户端环境显示,服务端不显示 toast ## 代码位置 - app/api/axios-client.ts:177-185 ## 实现 ```typescript // 🔒 403 无权限错误处理 if (isAxiosError(error) && error.response?.status === 403) { console.warn('⚠️ [403 Forbidden] 无权限访问:', error.config?.url); // 只在客户端显示 toast 提示 if (typeof window !== 'undefined') { toastService.warning('无权限访问该资源'); } } ``` ## 用户体验 - 用户访问无权限资源时,右上角显示黄色警告 toast - toast 自动消失,不阻塞用户操作 - 控制台同时输出警告日志便于调试
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse, isAxiosError } from 'axios';
|
||||
import { mockData, type MockApiResponse } from './mock';
|
||||
import { API_BASE_URL, DOCUMENT_URL } from '../config/api-config';
|
||||
import { toastService } from '../components/ui/Toast';
|
||||
|
||||
/**
|
||||
* API响应类型
|
||||
@@ -173,6 +174,16 @@ axiosInstance.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
|
||||
// 🔒 403 无权限错误处理
|
||||
if (isAxiosError(error) && error.response?.status === 403) {
|
||||
console.warn('⚠️ [403 Forbidden] 无权限访问:', error.config?.url);
|
||||
|
||||
// 只在客户端显示 toast 提示
|
||||
if (typeof window !== 'undefined') {
|
||||
toastService.warning('无权限访问该资源');
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user