|
|
@@ -113,17 +113,21 @@ const request = async <T>(url: string, options: RequestInit & { isToken?: boolea
|
|
|
|
|
|
// 若依后台返回格式处理
|
|
|
if (data.code !== 200) {
|
|
|
- // 保存错误信息到sessionStorage
|
|
|
- const errorInfo = {
|
|
|
- status: data.code,
|
|
|
- message: data.msg || '请求失败',
|
|
|
- resource: url,
|
|
|
- action: options.method || 'GET'
|
|
|
- };
|
|
|
- sessionStorage.setItem('errorInfo', JSON.stringify(errorInfo));
|
|
|
+ // 对于权限错误(403),保存错误信息并重定向到错误页面
|
|
|
+ if (data.code === 403) {
|
|
|
+ const errorInfo = {
|
|
|
+ status: data.code,
|
|
|
+ message: data.msg || '权限不足',
|
|
|
+ resource: url,
|
|
|
+ action: options.method || 'GET'
|
|
|
+ };
|
|
|
+ sessionStorage.setItem('errorInfo', JSON.stringify(errorInfo));
|
|
|
+
|
|
|
+ // 重定向到错误页面
|
|
|
+ window.location.href = '/error';
|
|
|
+ }
|
|
|
|
|
|
- // 重定向到错误页面
|
|
|
- window.location.href = '/error';
|
|
|
+ // 对于其他错误,直接抛出异常,让React Admin处理
|
|
|
throw new Error(data.msg || '请求失败');
|
|
|
}
|
|
|
|