fix: use AbortSignal.timeout for upload timeout

Replace manual AbortController+setTimeout with AbortSignal.timeout(),
fixing unreachable clearTimeout on error path and distinguishing
TimeoutError from AbortError for future cancel support.
This commit is contained in:
Johnpaul
2026-04-06 18:17:00 +01:00
parent fb559ac5ac
commit e93476174f

View File

@@ -29,17 +29,12 @@ const uploadFile = async (
if (isPasted) body.append('subfolder', 'pasted')
if (formFields.type) body.append('type', formFields.type)
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), UPLOAD_TIMEOUT_MS)
const resp = await api.fetchApi('/upload/image', {
method: 'POST',
body,
signal: controller.signal
signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS)
})
clearTimeout(timeoutId)
if (resp.status !== 200) {
useToastStore().addAlert(resp.status + ' - ' + resp.statusText)
return
@@ -95,7 +90,7 @@ export const useNodeImageUpload = (
if (!path) return
return path
} catch (error) {
if (error instanceof DOMException && error.name === 'AbortError') {
if (error instanceof DOMException && error.name === 'TimeoutError') {
useToastStore().addAlert(t('g.uploadTimedOut'))
} else {
useToastStore().addAlert(String(error))