From 77e78d55fc28249dea3831416ea90db2172d9e07 Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 7 Jun 2025 11:46:16 +0600 Subject: [PATCH] web/workers/fetch: catch network-related errors & retry 3 times previously all network issues showed a "worker crashed" error, which people misinterpreted all the time, and reasonably so --- web/i18n/en/error/queue.json | 1 + web/src/lib/task-manager/workers/fetch.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/web/i18n/en/error/queue.json b/web/i18n/en/error/queue.json index 44e60989..064dce5a 100644 --- a/web/i18n/en/error/queue.json +++ b/web/i18n/en/error/queue.json @@ -7,6 +7,7 @@ "fetch.no_file_reader": "couldn't write a file to cache", "fetch.empty_tunnel": "file tunnel is empty, try again in a few minutes", "fetch.corrupted_file": "file wasn't downloaded fully, try again", + "fetch.network_error": "downloading was interrupted by a network issue", "ffmpeg.probe_failed": "couldn't probe this file, it may be unsupported or corrupted", "ffmpeg.out_of_memory": "not enough available memory, can't continue", diff --git a/web/src/lib/task-manager/workers/fetch.ts b/web/src/lib/task-manager/workers/fetch.ts index 8d1fb8cf..d1bf4d8a 100644 --- a/web/src/lib/task-manager/workers/fetch.ts +++ b/web/src/lib/task-manager/workers/fetch.ts @@ -1,5 +1,10 @@ import * as Storage from "$lib/storage"; +const networkErrors = [ + "TypeError: Failed to fetch", + "TypeError: network error", +]; + let attempts = 0; const fetchFile = async (url: string) => { @@ -83,6 +88,10 @@ const fetchFile = async (url: string) => { } }); } catch (e) { + // retry several times if the error is network-related + if (networkErrors.includes(String(e))) { + return error("queue.fetch.network_error"); + } console.error("error from the fetch worker:"); console.error(e); return error("queue.fetch.crashed", false);