Compare commits

..
2 Commits
Author SHA1 Message Date
xrain e0754ad635 query 增加了自处理异常
Publish to npm / publish (push) Failing after 8s
2026-05-04 02:27:43 +08:00
xrain 39626de073 修复了退出登录 TOKEN没清空的问题
Publish to npm / publish (push) Failing after 14s
2026-05-04 00:15:23 +08:00
2 changed files with 77 additions and 73 deletions
+5 -2
View File
@@ -237,7 +237,8 @@ export class SimApiCore {
uri: string, uri: string,
params: any = {}, params: any = {},
endpointKey?: string, endpointKey?: string,
extraHeaders?: Record<string, string> extraHeaders?: Record<string, string>,
selfHandleError: boolean = false
): Promise<SimApiBaseResponse<T>> { ): Promise<SimApiBaseResponse<T>> {
const headers: Record<string, string> = {...extraHeaders, ...{}} const headers: Record<string, string> = {...extraHeaders, ...{}}
const queryId = this.genS4() const queryId = this.genS4()
@@ -271,11 +272,13 @@ export class SimApiCore {
const processedData = this.api.responseCallback.success(respData) as SimApiBaseResponse<T> const processedData = this.api.responseCallback.success(respData) as SimApiBaseResponse<T>
// 业务回调处理 // 业务回调处理
if (!selfHandleError) {
if (this.api.businessCallback.hasOwnProperty(processedData.code)) { if (this.api.businessCallback.hasOwnProperty(processedData.code)) {
this.api.businessCallback[processedData.code](processedData) this.api.businessCallback[processedData.code](processedData)
} else if (this.api.businessCallback['common'] && processedData.code !== 200) { } else if (this.api.businessCallback['common'] && processedData.code !== 200) {
this.api.businessCallback['common'](processedData) this.api.businessCallback['common'](processedData)
} }
}
// code != 200 时抛出业务错误 // code != 200 时抛出业务错误
if (processedData.code !== 200) { if (processedData.code !== 200) {
@@ -311,7 +314,7 @@ export class SimApiCore {
async logout(url?: string | null): Promise<any> { async logout(url?: string | null): Promise<any> {
if (url !== null) { if (url !== null) {
return this.query(url ?? this.auth.logout_url).catch(() => true) this.query(url ?? this.auth.logout_url).catch(() => true)
} }
this.removeToken() this.removeToken()
return true return true
+3 -2
View File
@@ -73,9 +73,10 @@ export const useSimApi = defineStore('simapi', {
uri: string, uri: string,
params?: any, params?: any,
endpointKey?: string, endpointKey?: string,
extraHeaders?: Record<string, string> extraHeaders?: Record<string, string>,
selfHandleError: boolean = false
): Promise<SimApiBaseResponse<T>> { ): 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 { getEndpoint(name?: string): string {