forked from 77media/video-flow
更新 处理402
This commit is contained in:
parent
f72e942a0b
commit
d597f418dd
@ -1,7 +1,7 @@
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios';
|
||||
import { baseUrl } from '@/lib/env';
|
||||
import { errorHandle } from './errorHandle';
|
||||
|
||||
import { showInsufficientPointsNotification } from '@/utils/notifications';
|
||||
/**
|
||||
* 统一的错误处理函数
|
||||
* @param error - 错误对象
|
||||
@ -52,22 +52,20 @@ request.interceptors.response.use(
|
||||
const businessCode = response.data?.code;
|
||||
const errorMessage = response.data?.message;
|
||||
// 其他业务错误
|
||||
if(businessCode === 402){
|
||||
showInsufficientPointsNotification();
|
||||
return {};
|
||||
}
|
||||
errorHandle(businessCode, errorMessage);
|
||||
return Promise.reject(new Error(errorMessage));
|
||||
}
|
||||
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
// 处理 402 错误
|
||||
if (error.response?.status === 402 && error.response?.data?.detail) {
|
||||
// 使用动态导入并确保在下一个事件循环中执行
|
||||
setTimeout(() => {
|
||||
import('../utils/notifications').then(({ showInsufficientPointsNotification }) => {
|
||||
showInsufficientPointsNotification(error.response.data.detail);
|
||||
});
|
||||
}, 0);
|
||||
|
||||
return Promise.reject(new Error('Insufficient points'));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user