From c16cbc638571ba0b7ca39ad3c6bf130b1006ddbd Mon Sep 17 00:00:00 2001 From: David Brooks Date: Wed, 12 Aug 2026 17:51:27 +1200 Subject: [PATCH 1/4] proxy: better handle missing file result from OpenCOR's CORS proxy. --- src/renderer/src/common/locCommon.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/common/locCommon.ts b/src/renderer/src/common/locCommon.ts index a1a80852..a44d6c41 100644 --- a/src/renderer/src/common/locCommon.ts +++ b/src/renderer/src/common/locCommon.ts @@ -188,14 +188,19 @@ export const file = ( } throw new Error( - `Failed to fetch the file through OpenCOR's CORS proxy. The server responded with a status of ${response.status}.` + `Failed to fetch the file through OpenCOR's CORS proxy. The server responded with a status of ${response.status}.`, { + cause: response.status + } ); }) .catch((error: unknown) => { // A network/CORS error is an instance of TypeError in fetch. So, if this is the case then we try fetching // the file directly otherwise we re-throw the error. - if (!(error instanceof TypeError)) { + if (!(error instanceof TypeError) + && (!(error instanceof Error) + || typeof(error.cause) !== 'number' + || ![403, 404].includes(error.cause))) { throw new Error(common.formatError(error)); } From 7efba6755293ac2d1fc96b80795f893d50e78715 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 12 Aug 2026 15:28:30 +0200 Subject: [PATCH 2/4] New version. --- package.json | 2 +- src/renderer/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3bd836ac..fa4b33dc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "url": "git+https://github.com/opencor/webapp.git" }, "type": "module", - "version": "1.20260813.0", + "version": "1.20260813.1", "engines": { "bun": ">=1.2.0" }, diff --git a/src/renderer/package.json b/src/renderer/package.json index 9b9a2742..3cba632f 100644 --- a/src/renderer/package.json +++ b/src/renderer/package.json @@ -42,7 +42,7 @@ }, "./style.css": "./dist/opencor.css" }, - "version": "1.20260813.0", + "version": "1.20260813.1", "libopencorVersion": "1.20260803.0", "scripts": { "build": "vite build && bun scripts/generate.version.ts", From 6b6e7e2d02413c5b97156de23574afca00b9971d Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 12 Aug 2026 15:28:48 +0200 Subject: [PATCH 3/4] Formatting. --- src/renderer/src/common/locCommon.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/common/locCommon.ts b/src/renderer/src/common/locCommon.ts index a44d6c41..5294fd18 100644 --- a/src/renderer/src/common/locCommon.ts +++ b/src/renderer/src/common/locCommon.ts @@ -188,7 +188,8 @@ export const file = ( } throw new Error( - `Failed to fetch the file through OpenCOR's CORS proxy. The server responded with a status of ${response.status}.`, { + `Failed to fetch the file through OpenCOR's CORS proxy. The server responded with a status of ${response.status}.`, + { cause: response.status } ); @@ -197,10 +198,10 @@ export const file = ( // A network/CORS error is an instance of TypeError in fetch. So, if this is the case then we try fetching // the file directly otherwise we re-throw the error. - if (!(error instanceof TypeError) - && (!(error instanceof Error) - || typeof(error.cause) !== 'number' - || ![403, 404].includes(error.cause))) { + if ( + !(error instanceof TypeError) && + (!(error instanceof Error) || typeof error.cause !== 'number' || ![403, 404].includes(error.cause)) + ) { throw new Error(common.formatError(error)); } From 65a33b263741b1d880f09c7b06875b393e531d84 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 12 Aug 2026 15:40:55 +0200 Subject: [PATCH 4/4] Clarify the fallback logic in the file() method. --- src/renderer/src/common/locCommon.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/common/locCommon.ts b/src/renderer/src/common/locCommon.ts index 5294fd18..4fa19192 100644 --- a/src/renderer/src/common/locCommon.ts +++ b/src/renderer/src/common/locCommon.ts @@ -187,6 +187,8 @@ export const file = ( return response.arrayBuffer(); } + // If the fetch through OpenCOR's CORS proxy failed, then throw an error to trigger the catch block below. + throw new Error( `Failed to fetch the file through OpenCOR's CORS proxy. The server responded with a status of ${response.status}.`, { @@ -195,8 +197,8 @@ export const file = ( ); }) .catch((error: unknown) => { - // A network/CORS error is an instance of TypeError in fetch. So, if this is the case then we try fetching - // the file directly otherwise we re-throw the error. + // If the fetch through OpenCOR's CORS proxy failed, then try fetching the URL directly, unless the error + // was a TypeError or an HTTP 403 or 404 error. if ( !(error instanceof TypeError) &&