refactor(frontend): split large reimbursement and audit modules
This commit is contained in:
@@ -6,6 +6,12 @@ const backendHealthy = ref(true)
|
||||
const backendChecking = ref(false)
|
||||
const backendError = ref('')
|
||||
let lastCheckedAt = 0
|
||||
const DEFAULT_HEALTH_TIMEOUT_MS = 2500
|
||||
const REQUEST_TIMEOUT_CODE = 'REQUEST_TIMEOUT'
|
||||
|
||||
function isRequestTimeout(error) {
|
||||
return error?.code === REQUEST_TIMEOUT_CODE
|
||||
}
|
||||
|
||||
export async function checkBackendHealth(options = {}) {
|
||||
const force = Boolean(options.force)
|
||||
@@ -18,7 +24,9 @@ export async function checkBackendHealth(options = {}) {
|
||||
backendChecking.value = true
|
||||
|
||||
try {
|
||||
const payload = await fetchBackendHealth()
|
||||
const payload = await fetchBackendHealth({
|
||||
timeoutMs: Number(options.timeoutMs || DEFAULT_HEALTH_TIMEOUT_MS)
|
||||
})
|
||||
const ok = payload?.status === 'ok'
|
||||
|
||||
backendHealthy.value = ok
|
||||
@@ -28,6 +36,12 @@ export async function checkBackendHealth(options = {}) {
|
||||
lastCheckedAt = now
|
||||
return ok
|
||||
} catch (error) {
|
||||
if (isRequestTimeout(error) && options.allowStaleOnTimeout) {
|
||||
backendError.value = error?.message || '后端正在处理耗时任务,已先展示页面。'
|
||||
lastCheckedAt = now
|
||||
return backendHealthy.value !== false
|
||||
}
|
||||
|
||||
backendHealthy.value = false
|
||||
backendError.value = error?.message || '无法连接后端服务。'
|
||||
lastCheckedAt = now
|
||||
|
||||
Reference in New Issue
Block a user