Check status code instead of throwing error

This commit is contained in:
RMidhunSuresh 2022-08-16 14:32:18 +05:30
parent 08f9edaf68
commit 5d63069f31
2 changed files with 9 additions and 8 deletions

View File

@ -119,10 +119,11 @@ export function createFetchRequest(createTimeout, serviceWorkerHandler) {
body = await response.text(); body = await response.text();
} }
} catch (err) { } catch (err) {
if (err.name === "SyntaxError" && status >= 400) { // some error pages return html instead of json, ignore error
throw new ConnectionError(`${method} ${url}: Failed to fetch JSON file!`); // detect these ignored errors from the response status
if (!(err.name === "SyntaxError" && status >= 400)) {
throw err;
} }
throw err;
} }
return {status, body}; return {status, body};
}, err => { }, err => {

View File

@ -37,7 +37,7 @@ export class ThemeLoader {
let noManifestsAvailable = true; let noManifestsAvailable = true;
const failedManifestLoads: string[] = []; const failedManifestLoads: string[] = [];
const parseErrors: 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()) manifestLocations.map(location => this._platform.request(location, { method: "GET", format: "json", cache: true, }).response())
); );
const runtimeThemeParser = new RuntimeThemeParser(this._platform, this.preferredColorScheme); const runtimeThemeParser = new RuntimeThemeParser(this._platform, this.preferredColorScheme);
@ -45,14 +45,14 @@ export class ThemeLoader {
const runtimeThemePromises: Promise<void>[] = []; const runtimeThemePromises: Promise<void>[] = [];
for (let i = 0; i < results.length; ++i) { for (let i = 0; i < results.length; ++i) {
const result = results[i]; const result = results[i];
if (result.status === "rejected") { const { status, body } = result;
console.error(`Failed to load manifest at ${manifestLocations[i]}, reason: ${result.reason}`); if (!(status >= 200 && status <= 299)) {
log.log({ l: "Manifest fetch failed", location: manifestLocations[i], reason: result.reason }, LogLevel.Error); 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]) failedManifestLoads.push(manifestLocations[i])
continue; continue;
} }
noManifestsAvailable = false; noManifestsAvailable = false;
const { body } = result.value;
try { try {
if (body.extends) { if (body.extends) {
const indexOfBaseManifest = results.findIndex(result => "value" in result && result.value.body.id === body.extends); const indexOfBaseManifest = results.findIndex(result => "value" in result && result.value.body.id === body.extends);