From 273ce5d1dd2c5bd3e1e27f96f0c065175cd9a876 Mon Sep 17 00:00:00 2001 From: bitWolfy Date: Thu, 8 Feb 2024 14:49:21 -0800 Subject: [PATCH] [SubscriptionTracker] Add proper error handling --- src/js/components/utility/Util.ts | 2 -- src/js/components/utility/UtilNetwork.ts | 25 ------------------- .../subscriptions/_SubscriptionManager.ts | 17 ++----------- .../subscriptions/_SubscriptionTracker.ts | 6 +++-- 4 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 src/js/components/utility/UtilNetwork.ts diff --git a/src/js/components/utility/Util.ts b/src/js/components/utility/Util.ts index 62930aaa..9aaec5cb 100644 --- a/src/js/components/utility/Util.ts +++ b/src/js/components/utility/Util.ts @@ -2,7 +2,6 @@ import { UtilDOM } from "./UtilDOM"; import { UtilEvents } from "./UtilEvents"; import { UtilID } from "./UtilID"; import { UtilMath } from "./UtilMath"; -import { UtilNetwork } from "./UtilNetwork"; import { UtilSize } from "./UtilSize"; import { UtilTime } from "./UtilTime"; @@ -15,7 +14,6 @@ export class Util { public static Events = UtilEvents; public static ID = UtilID; public static Math = UtilMath; - public static Network = UtilNetwork; public static Time = UtilTime; public static Size = UtilSize; diff --git a/src/js/components/utility/UtilNetwork.ts b/src/js/components/utility/UtilNetwork.ts deleted file mode 100644 index 0e289063..00000000 --- a/src/js/components/utility/UtilNetwork.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { XM } from "../api/XM"; - -export class UtilNetwork { - - public static async isOnline(): Promise { - - // Not terribly reliable. - // If the computer is connected to any network, including LAN, this - // will return true. So, if there's a connection to the router, but - // not to the internet as a whole, this will not work. - if (!navigator.onLine) return Promise.resolve(false); - - // Fallback method - // Tries to make a HEAD request to e621.net, and checks if it works - return new Promise((resolve) => { - XM.Connect.xmlHttpRequest({ - method: "HEAD", - url: window.location.host == "e621.net" ? "https://e621.net/" : "https://e926.net/", - onerror: () => { resolve(false); }, - onload: () => { resolve(true); }, - }); - }) - } - -} diff --git a/src/js/modules/subscriptions/_SubscriptionManager.ts b/src/js/modules/subscriptions/_SubscriptionManager.ts index fc6ba285..016f8975 100644 --- a/src/js/modules/subscriptions/_SubscriptionManager.ts +++ b/src/js/modules/subscriptions/_SubscriptionManager.ts @@ -36,7 +36,6 @@ export class SubscriptionManager extends RE6Module { cacheVersion: 0, // utility variable, cache is cleared if it does not match the hardcoded one - skipPreflightChecks: false, // suppresses the network status check before the update loadLargeThumbs: false, // replaces the preview-sized thumbnails with (animated) sample sized ones windowWidth: "37", // width of the notifications window, in REM @@ -284,18 +283,6 @@ export class SubscriptionManager extends RE6Module { } ), - Form.checkbox( - { - value: this.fetchSettings("skipPreflightChecks"), - label: "Skip Preflight Checks
Disables the extra network checks before updating the subscriptions", - width: 2, - }, - async (data) => { - await this.pushSettings("skipPreflightChecks", data); - } - ), - Form.spacer(2, true), - Form.checkbox( { value: this.fetchSettings("loadLargeThumbs"), @@ -437,8 +424,8 @@ export class SubscriptionManager extends RE6Module { } if (instance.isNetworkOffline()) { - $el.val("Network Offline") - .attr("title", "Unable to reach e621 servers.\nPlease, check your Internet connection.") + $el.val("Error") + .attr("title", "At least one update request failed to complete.") .addClass("failed-attempt"); eventLock = false; return; diff --git a/src/js/modules/subscriptions/_SubscriptionTracker.ts b/src/js/modules/subscriptions/_SubscriptionTracker.ts index df26287a..39f4bbd2 100644 --- a/src/js/modules/subscriptions/_SubscriptionTracker.ts +++ b/src/js/modules/subscriptions/_SubscriptionTracker.ts @@ -2,6 +2,7 @@ import { XM } from "../../components/api/XM"; import { Page } from "../../components/data/Page"; import { ModuleController } from "../../components/ModuleController"; import { RE6Module, Settings } from "../../components/RE6Module"; +import { ErrorHandler } from "../../components/utility/ErrorHandler"; import { Util } from "../../components/utility/Util"; import { SubscriptionCache, UpdateContent, UpdateData } from "./_SubscriptionCache"; import { SubscriptionList } from "./_SubscriptionList"; @@ -397,14 +398,15 @@ export class SubscriptionTracker extends RE6Module { this.updateInProgress = true; SubscriptionManager.trigger("inprogress." + this.trackerID, 0); - if (ModuleController.fetchSettings(SubscriptionManager, "skipPreflightChecks") || await Util.Network.isOnline()) { + try { this.execPreUpdate(); await this.cache.fetch(); this.execPostUpdate(); this.networkOffline = false; this.updateInProgress = false; SubscriptionManager.trigger("inprogress." + this.trackerID, 2); - } else { + } catch(error) { + ErrorHandler.error(this, JSON.stringify(error), "update"); this.networkOffline = true; this.updateInProgress = false; SubscriptionManager.trigger("inprogress." + this.trackerID, 3);