From 988582e9dfdc0dcf4c05e297c84ae5bd7472bbee Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sun, 21 Jun 2026 15:35:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(common):=20useRequest.fetchAsync=20?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E9=87=8D=E5=A4=8D=E5=8C=85=E8=A3=85=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=8B=A6=E6=88=AA=E5=99=A8=E5=B7=B2=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9A=84=20RequestError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 响应拦截器(如 useApi.ts 中的错误转换)产生的 RequestError 会被 fetchAsync 的 catch 块再次包装为 RequestError('网络请求失败', 'OtherError'), 导致原始的服务器错误消息(如"系统异常")丢失。 现在当 catch 块收到的错误已经是 RequestError 时,直接透传而不重新包装, 保留拦截器中已经提取好的错误消息。 Co-Authored-By: Claude Sonnet 4.6 --- packages/common/src/api/useRequest.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/common/src/api/useRequest.ts b/packages/common/src/api/useRequest.ts index 1865e40..6787701 100644 --- a/packages/common/src/api/useRequest.ts +++ b/packages/common/src/api/useRequest.ts @@ -202,6 +202,14 @@ export function useRequest< } catch (e: unknown) { clearTimeout(timer) + // If a response interceptor already produced a RequestError, pass it through + // rather than re-wrapping it and losing the original message. + if (e instanceof RequestError) { + _notifyApiError(e) + dispatch({ type: 'reject', error: e }) + return Promise.reject(e) + } + let wrapped: RequestError if (isCancel(e)) {