Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
fix: translate refusals that arrive during a transfer (#169)
Anzy7cc640e6328d
diff --git a/e2e/errors.spec.ts b/e2e/errors.spec.tsnew file mode 100644index 0000000..6d7222c--- /dev/null+++ b/e2e/errors.spec.ts@@ -0,0 +1,28 @@+import { expect, test } from '@playwright/test'+import { describeError, linkRefused } from '../src/shared/errors'+import type { HttpDownloadState } from '../src/shared/types'+import { linkExpired } from '../src/renderer/src/utils/format'++const refused = (status: number): string =>+ `Unexpected status ${status} for range request (http://host/file.zip)`++const errorDownload = (error: string): HttpDownloadState =>+ ({ kind: 'http', status: 'error', error }) as HttpDownloadState++test.describe('refused links @smoke', () => {+ for (const status of [401, 403, 404, 410, 416]) {+ test(`${status} during a transfer reads as a dead link`, () => {+ expect(describeError(refused(status))).toBe(+ 'This link no longer works. Paste a new link to continue.'+ )+ expect(linkRefused(refused(status))).toBe(true)+ expect(linkExpired(errorDownload(refused(status)))).toBe(true)+ })+ }++ test('a server error is not a dead link', () => {+ expect(describeError(refused(503))).toBe('The server is having trouble. Try again later.')+ expect(linkRefused(refused(503))).toBe(false)+ expect(linkExpired(errorDownload(refused(503)))).toBe(false)+ })+})diff --git a/src/renderer/src/utils/format.ts b/src/renderer/src/utils/format.tsindex 57f0f29..3353ba8 100644--- a/src/renderer/src/utils/format.ts+++ b/src/renderer/src/utils/format.ts@@ -1,3 +1,4 @@+import { describeError, linkRefused } from '@shared/errors'import type {DownloadNetwork,DownloadState,@@ -276,18 +277,12 @@ export function toDisplayPath(path: string, homeDir: string): string {return `~${suffix.replace(/\//g, sep)}`}-export { describeError } from '@shared/errors'--const LINK_REFUSED = /status (401|403|404|410|416) for range request/+export { describeError }/** A download whose link the server now refuses: a fresh link to the same file picks it up.* 416 (Range Not Satisfiable) belongs here too: the server is saying the byte range this* download was resuming no longer exists, same as a 404/410 — retrying the same range would* just repeat the same 416 forever. */export function linkExpired(download: DownloadState): boolean {- return (- download.kind === 'http' &&- download.status === 'error' &&- LINK_REFUSED.test(download.error ?? '')- )+ return download.kind === 'http' && download.status === 'error' && linkRefused(download.error)}diff --git a/src/shared/errors.ts b/src/shared/errors.tsindex 6705a73..bbcaa60 100644--- a/src/shared/errors.ts+++ b/src/shared/errors.ts@@ -2,7 +2,13 @@ const IPC_INVOKE_PREFIX = /^Error invoking remote method '[^']*':\s*/const NESTED_ERROR_PREFIX = /^Error:\s*//** A link that worked and then stopped: signed links run out, and a server turns them away. */-const LINK_REFUSED = /status (401|403|404|410) for range request/+const LINK_REFUSED = /status (401|403|404|410|416) for range request/++/** Whether an error says the server refused this download's byte range: its link is no longer+ * good, and a fresh one to the same file is what carries on. */+export function linkRefused(error: string | undefined | null): boolean {+ return !!error && LINK_REFUSED.test(error)+}const ERROR_HINTS: Array<{ pattern: RegExp; message: string }> = [{@@ -89,23 +95,23 @@ const ERROR_HINTS: Array<{ pattern: RegExp; message: string }> = [message: 'That doesn’t look like a valid link.'},{- pattern: /Server responded with status 401/,+ pattern: /(?:Server responded with|Unexpected) status 401\b/,message: 'This link requires authentication. Try a direct download link.'},{- pattern: /Server responded with status 403/,+ pattern: /(?:Server responded with|Unexpected) status 403\b/,message: 'The server denied access to this file. Check the link or try a new one.'},{- pattern: /Server responded with status 404/,+ pattern: /(?:Server responded with|Unexpected) status 404\b/,message: 'The file couldn’t be found. Check the link and try again.'},{- pattern: /Server responded with status 4\d\d/,+ pattern: /(?:Server responded with|Unexpected) status 4\d\d\b/,message: 'The server rejected the download. Check the link and try again.'},{- pattern: /Server responded with status 5\d\d/,+ pattern: /(?:Server responded with|Unexpected) status 5\d\d\b/,message: 'The server is having trouble. Try again later.'}]