From 10fa9b68d3c41d70c0ecad35f3be52eed3335c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arno=2C=E9=99=86=E5=9D=A1?= Date: Thu, 16 Oct 2025 09:51:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BD=93http=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81=E4=B8=BA200=EF=BC=8C=E4=B8=9A=E5=8A=A1code?= =?UTF-8?q?=E4=B8=BA=E9=94=99=E8=AF=AF=E7=A0=81=E4=B8=AD=E6=96=ADpromise?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/http.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/http/http.ts b/src/http/http.ts index eafe8e0..29f48d0 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -96,9 +96,20 @@ export function http(options: CustomRequestOptions) { if (res.statusCode >= 200 && res.statusCode < 300) { // 处理业务逻辑错误 if (code !== ResultEnum.Success0 && code !== ResultEnum.Success200) { - throw new Error(`请求错误[${code}]:${responseData.message || responseData.msg}`) + uni.showToast({ + icon: 'none', + title: responseData.msg || responseData.message || '请求错误', + }) + //这里不直接抛出错误,会中断promise链条,无法进入finally,在下方return resolve(responseData as T)继续执行,在接口调用可通过判断code来处理业务逻辑 + //async getSampleEnums() { + // const res = await getSampleEnumsApi(); + // if (res.code === ResultEnum.Success200) { + // // 处理成功 + // } + //}, + //throw new Error(`请求错误[${code}]:${responseData.message || responseData.msg}`) } - return resolve(responseData.data as T) + return resolve(responseData as T) } // 处理其他错误