From 608e7bf814420a4d8c8a3f110ff68d7112528d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?= <7854742+wang_rumeng@user.noreply.gitee.com> Date: Sun, 7 Sep 2025 05:33:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E4=B8=8D=E8=B6=B3=E5=BC=B9=E7=AA=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/request.ts | 14 +++++--------- utils/notifications.tsx | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) 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: (