diff --git a/api/request.ts b/api/request.ts index f5f123f..4bc2b41 100644 --- a/api/request.ts +++ b/api/request.ts @@ -14,24 +14,20 @@ const handleRequestError = (error: any, defaultMessage: string = '请求失败') // 处理 402 状态码的特殊情况 if (status === 402 && data?.detail) { - import('./errorHandle').then(({ errorHandle }) => { - errorHandle(status, errorMessage); - // 调用积分不足通知,传入详细信息 - import('../utils/notifications').then(({ showInsufficientPointsNotification }) => { - showInsufficientPointsNotification(data.detail); - }); + // 只显示通知,不调用 errorHandle + import('../utils/notifications').then(({ showInsufficientPointsNotification }) => { + showInsufficientPointsNotification(data.detail); }); - return; + return; // 直接返回,不再抛出错误 } errorHandle(status, errorMessage); } else if (error.request) { - // 请求已发出但没有收到响应 errorHandle(0); } else { - // 请求配置出错 errorHandle(0, error.message || defaultMessage); } + return Promise.reject(error); // 将 reject 移到这里,避免 402 时重复处理 }; // 创建 axios 实例 const request: AxiosInstance = axios.create({ diff --git a/utils/notifications.tsx b/utils/notifications.tsx index db8e313..a44bbcd 100644 --- a/utils/notifications.tsx +++ b/utils/notifications.tsx @@ -63,7 +63,11 @@ export const showInsufficientPointsNotification = (detail?: { required_tokens?: number; message?: string; }) => { + // 生成唯一的 key + const key = `insufficient-points-${Date.now()}`; + notification.warning({ + key, // 添加唯一的 key message: null, description: (