From 5d63069f317fd3d553c7121e90537a8e88e2e88b Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 16 Aug 2022 14:32:18 +0530 Subject: [PATCH] Check status code instead of throwing error --- src/platform/web/dom/request/fetch.js | 7 ++++--- src/platform/web/theming/ThemeLoader.ts | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/platform/web/dom/request/fetch.js b/src/platform/web/dom/request/fetch.js index 5f6dcb65..c2e2d4b7 100644 --- a/src/platform/web/dom/request/fetch.js +++ b/src/platform/web/dom/request/fetch.js @@ -119,10 +119,11 @@ export function createFetchRequest(createTimeout, serviceWorkerHandler) { body = await response.text(); } } catch (err) { - if (err.name === "SyntaxError" && status >= 400) { - throw new ConnectionError(`${method} ${url}: Failed to fetch JSON file!`); + // some error pages return html instead of json, ignore error + // detect these ignored errors from the response status + if (!(err.name === "SyntaxError" && status >= 400)) { + throw err; } - throw err; } return {status, body}; }, err => { diff --git a/src/platform/web/theming/ThemeLoader.ts b/src/platform/web/theming/ThemeLoader.ts index 6382dcdb..665c3a17 100644 --- a/src/platform/web/theming/ThemeLoader.ts +++ b/src/platform/web/theming/ThemeLoader.ts @@ -37,7 +37,7 @@ export class ThemeLoader { let noManifestsAvailable = true; const failedManifestLoads: string[] = []; const parseErrors: string[] = []; - const results = await Promise.allSettled( + const results = await Promise.all( manifestLocations.map(location => this._platform.request(location, { method: "GET", format: "json", cache: true, }).response()) ); const runtimeThemeParser = new RuntimeThemeParser(this._platform, this.preferredColorScheme); @@ -45,14 +45,14 @@ export class ThemeLoader { const runtimeThemePromises: Promise[] = []; for (let i = 0; i < results.length; ++i) { const result = results[i]; - if (result.status === "rejected") { - console.error(`Failed to load manifest at ${manifestLocations[i]}, reason: ${result.reason}`); - log.log({ l: "Manifest fetch failed", location: manifestLocations[i], reason: result.reason }, LogLevel.Error); + const { status, body } = result; + if (!(status >= 200 && status <= 299)) { + console.error(`Failed to load manifest at ${manifestLocations[i]}, status: ${status}`); + log.log({ l: "Manifest fetch failed", location: manifestLocations[i], status }, LogLevel.Error); failedManifestLoads.push(manifestLocations[i]) continue; } noManifestsAvailable = false; - const { body } = result.value; try { if (body.extends) { const indexOfBaseManifest = results.findIndex(result => "value" in result && result.value.body.id === body.extends);