Bluesky app fork with some witchin' additions 💫

Improve image download timeout handling (#9276)

authored by samuel.fm and committed by

GitHub 9070fa9a 55e9298e

+10 -3
+10 -3
src/lib/media/manip.ts
··· 410 410 411 411 async function downloadImage(uri: string, path: string, timeout: number) { 412 412 const dlResumable = createDownloadResumable(uri, path, {cache: true}) 413 - 414 - const to1 = setTimeout(() => dlResumable.cancelAsync(), timeout) 413 + let timedOut = false 414 + const to1 = setTimeout(() => { 415 + timedOut = true 416 + dlResumable.cancelAsync() 417 + }, timeout) 415 418 416 419 const dlRes = await dlResumable.downloadAsync() 417 420 clearTimeout(to1) 418 421 419 422 if (!dlRes?.uri) { 420 - throw new Error('Failed to download image - dlRes is undefined') 423 + if (timedOut) { 424 + throw new Error('Failed to download image - timed out') 425 + } else { 426 + throw new Error('Failed to download image - dlRes is undefined') 427 + } 421 428 } 422 429 423 430 return normalizePath(dlRes.uri)