From 9070fa9a8d3f81780a55a9dced85770fed689cd4 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 3 Nov 2025 19:11:29 +0200 Subject: [PATCH] Improve image download timeout handling (#9276) --- src/lib/media/manip.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index bf6843f542..423a65e86b 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -410,14 +410,21 @@ function createPath(ext: string) { async function downloadImage(uri: string, path: string, timeout: number) { const dlResumable = createDownloadResumable(uri, path, {cache: true}) - - const to1 = setTimeout(() => dlResumable.cancelAsync(), timeout) + let timedOut = false + const to1 = setTimeout(() => { + timedOut = true + dlResumable.cancelAsync() + }, timeout) const dlRes = await dlResumable.downloadAsync() clearTimeout(to1) if (!dlRes?.uri) { - throw new Error('Failed to download image - dlRes is undefined') + if (timedOut) { + throw new Error('Failed to download image - timed out') + } else { + throw new Error('Failed to download image - dlRes is undefined') + } } return normalizePath(dlRes.uri)