query 增加了自处理异常
Publish to npm / publish (push) Failing after 8s
Publish to npm / publish (push) Failing after 8s
This commit is contained in:
+4
-1
@@ -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) {
|
||||
|
||||
+3
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user