Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2f57bc419 | ||
|
|
fe77c0ee1a |
+17
-3
@@ -27,6 +27,7 @@ export type {
|
|||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
declare const SimApiVersion: string;
|
declare const SimApiVersion: string;
|
||||||
|
declare const AppVersion: string;
|
||||||
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
||||||
|
|
||||||
function fetchWithTimeout(
|
function fetchWithTimeout(
|
||||||
@@ -203,7 +204,7 @@ export class SimApiCore {
|
|||||||
*/
|
*/
|
||||||
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
||||||
const versions: SimApiVersions = {
|
const versions: SimApiVersions = {
|
||||||
uiApp: '0.0.0-develop',
|
uiApp: typeof AppVersion === 'undefined' ? "0.0.0-develop" : AppVersion,
|
||||||
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
|
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
|
||||||
apiApp: '0.0.0',
|
apiApp: '0.0.0',
|
||||||
apiSimApi: '0.0.0',
|
apiSimApi: '0.0.0',
|
||||||
@@ -273,13 +274,26 @@ export class SimApiCore {
|
|||||||
this.api.businessCallback['common'](processedData)
|
this.api.businessCallback['common'](processedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接返回,不再根据 code 抛出错误
|
// code != 200 时抛出业务错误
|
||||||
|
if (processedData.code !== 200) {
|
||||||
|
throw processedData
|
||||||
|
}
|
||||||
return processedData
|
return processedData
|
||||||
} catch (error) {
|
|
||||||
|
} catch (error: any) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log('[RESPONSE]', queryId, '->', error)
|
console.log('[RESPONSE]', queryId, '->', error)
|
||||||
}
|
}
|
||||||
|
// 网络/HTTP 错误:包装成标准响应格式抛出
|
||||||
|
if (!error?.code) {
|
||||||
this.api.responseCallback.error(error)
|
this.api.responseCallback.error(error)
|
||||||
|
throw {
|
||||||
|
code: -1,
|
||||||
|
message: error?.message || '网络错误',
|
||||||
|
data: error,
|
||||||
|
} as SimApiBaseResponse<T>
|
||||||
|
}
|
||||||
|
// 业务错误直接抛出
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
"noUnusedLocals": false,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": false,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true
|
"emitDecoratorMetadata": true
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user