Compare commits

...
1 Commits
Author SHA1 Message Date
xrain e0754ad635 query 增加了自处理异常
Publish to npm / publish (push) Failing after 8s
2026-05-04 02:27:43 +08:00
2 changed files with 76 additions and 72 deletions
+4 -1
View File
@@ -237,7 +237,8 @@ export class SimApiCore {
uri: string,
params: any = {},
endpointKey?: string,
extraHeaders?: Record<string, string>
extraHeaders?: Record<string, string>,
selfHandleError: boolean = false
): Promise<SimApiBaseResponse<T>> {
const headers: Record<string, string> = {...extraHeaders, ...{}}
const queryId = this.genS4()
@@ -271,11 +272,13 @@ export class SimApiCore {
const processedData = this.api.responseCallback.success(respData) as SimApiBaseResponse<T>
// 业务回调处理
if (!selfHandleError) {
if (this.api.businessCallback.hasOwnProperty(processedData.code)) {
this.api.businessCallback[processedData.code](processedData)
} else if (this.api.businessCallback['common'] && processedData.code !== 200) {
this.api.businessCallback['common'](processedData)
}
}
// code != 200 时抛出业务错误
if (processedData.code !== 200) {
+6 -5
View File
@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'
import { SimApiCore } from './simapi.core'
import type { SimApiBaseResponse, SimApiOptions, SimApiVersions } from './types'
import {defineStore} from 'pinia'
import {SimApiCore} from './simapi.core'
import type {SimApiBaseResponse, SimApiOptions, SimApiVersions} from './types'
// ============ Pinia Store ============
// 仅作为 core 的代理映射,不维护任何独立状态
@@ -73,9 +73,10 @@ export const useSimApi = defineStore('simapi', {
uri: string,
params?: any,
endpointKey?: string,
extraHeaders?: Record<string, string>
extraHeaders?: Record<string, string>,
selfHandleError: boolean = false
): Promise<SimApiBaseResponse<T>> {
return this._core.query<T>(uri, params, endpointKey, extraHeaders)
return this._core.query<T>(uri, params, endpointKey, extraHeaders, selfHandleError)
},
getEndpoint(name?: string): string {