From fe77c0ee1aece1ee30fbe79f51def5cbc8e149d0 Mon Sep 17 00:00:00 2001 From: xRain Date: Wed, 22 Apr 2026 22:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/simapi.core.ts | 19 ++++++++++++++++--- tsconfig.json | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/simapi.core.ts b/src/simapi.core.ts index 5cd1ada..bf5c347 100644 --- a/src/simapi.core.ts +++ b/src/simapi.core.ts @@ -273,13 +273,26 @@ export class SimApiCore { this.api.businessCallback['common'](processedData) } - // 直接返回,不再根据 code 抛出错误 + // code != 200 时抛出业务错误 + if (processedData.code !== 200) { + throw processedData + } return processedData - } catch (error) { + + } catch (error: any) { if (this.debug) { console.log('[RESPONSE]', queryId, '->', error) } - this.api.responseCallback.error(error) + // 网络/HTTP 错误:包装成标准响应格式抛出 + if (!error?.code) { + this.api.responseCallback.error(error) + throw { + code: -1, + message: error?.message || '网络错误', + data: error, + } as SimApiBaseResponse + } + // 业务错误直接抛出 throw error } } diff --git a/tsconfig.json b/tsconfig.json index da27668..d7fd37d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,8 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noFallthroughCasesInSwitch": true, + "allowJs": true, + "checkJs": false, "experimentalDecorators": true, "emitDecoratorMetadata": true },