Improve image download timeout handling (#9276)
This commit is contained in:
+10
-3
@@ -410,14 +410,21 @@ function createPath(ext: string) {
|
|||||||
|
|
||||||
async function downloadImage(uri: string, path: string, timeout: number) {
|
async function downloadImage(uri: string, path: string, timeout: number) {
|
||||||
const dlResumable = createDownloadResumable(uri, path, {cache: true})
|
const dlResumable = createDownloadResumable(uri, path, {cache: true})
|
||||||
|
let timedOut = false
|
||||||
const to1 = setTimeout(() => dlResumable.cancelAsync(), timeout)
|
const to1 = setTimeout(() => {
|
||||||
|
timedOut = true
|
||||||
|
dlResumable.cancelAsync()
|
||||||
|
}, timeout)
|
||||||
|
|
||||||
const dlRes = await dlResumable.downloadAsync()
|
const dlRes = await dlResumable.downloadAsync()
|
||||||
clearTimeout(to1)
|
clearTimeout(to1)
|
||||||
|
|
||||||
if (!dlRes?.uri) {
|
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)
|
return normalizePath(dlRes.uri)
|
||||||
|
|||||||
Reference in New Issue
Block a user