Refaktor calendar error once again for better messaging to the user

This commit is contained in:
veeck 2021-05-02 10:28:11 +02:00
parent d43a57af36
commit 06b3f92963
3 changed files with 8 additions and 11 deletions

View File

@ -146,12 +146,9 @@ Module.register("calendar", {
this.broadcastEvents(); this.broadcastEvents();
} }
} }
} else if (notification === "FETCH_ERROR") { } else if (notification === "CALENDAR_ERROR") {
this.error = this.translate("MODULE_CONFIG_ERROR", { MODULE_NAME: this.name, ERROR: payload.error }); this.error = this.translate("MODULE_CONFIG_ERROR", { MODULE_NAME: this.name, ERROR: payload.error });
this.loaded = true; this.loaded = true;
} else if (notification === "INCORRECT_URL") {
this.error = `Incorrect url: ${payload.url}`;
this.loaded = true;
} }
this.updateDom(this.config.animationSpeed); this.updateDom(this.config.animationSpeed);

View File

@ -78,7 +78,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
maximumNumberOfDays maximumNumberOfDays
}); });
} catch (error) { } catch (error) {
fetchFailedCallback(this, error.message); fetchFailedCallback(this, error);
scheduleTimer(); scheduleTimer();
return; return;
} }
@ -86,7 +86,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
scheduleTimer(); scheduleTimer();
}) })
.catch((error) => { .catch((error) => {
fetchFailedCallback(this, error.message); fetchFailedCallback(this, error);
scheduleTimer(); scheduleTimer();
}); });
}; };

View File

@ -40,7 +40,8 @@ module.exports = NodeHelper.create({
try { try {
new URL(url); new URL(url);
} catch (error) { } catch (error) {
this.sendSocketNotification("INCORRECT_URL", { id: identifier, url: url }); Log.error("Calendar Error. Malformed calendar url: ", url, error);
this.sendSocketNotification("CALENDAR_ERROR", { error_type: "MODULE_ERROR_MALFORMED_URL" });
return; return;
} }
@ -55,10 +56,9 @@ module.exports = NodeHelper.create({
fetcher.onError((fetcher, error) => { fetcher.onError((fetcher, error) => {
Log.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); Log.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error);
this.sendSocketNotification("FETCH_ERROR", { let error_type = NodeHelper.checkFetchError(error);
id: identifier, this.sendSocketNotification("CALENDAR_ERROR", {
url: fetcher.url(), error_type
error: error
}); });
}); });