mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user