From a193a6923c2b37730c92d536a6d26a3c86e40425 Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Sat, 4 Feb 2023 18:05:47 +0100 Subject: [PATCH] fix(js): replace deprecated substr() with substring() and add checks for promise results --- src/background.js | 7 ++++--- src/popup.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/background.js b/src/background.js index 6cb728c..5dc2d2a 100644 --- a/src/background.js +++ b/src/background.js @@ -53,9 +53,10 @@ async function fetchNewData() { return; } try { - const result = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]); - const calendarJson = result[0].value; - const spaceApiJson = result[1].value; + const [resultCalendar, resultSpaceApi] = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]); + + const calendarJson = (resultCalendar.status === 'fulfilled') ? resultCalendar.value : undefined; + const spaceApiJson = (resultSpaceApi.status === 'fulfilled') ? resultSpaceApi.value : undefined; if (spaceApiJson) { const now = new Date(); diff --git a/src/popup.js b/src/popup.js index ab86653..30890a1 100644 --- a/src/popup.js +++ b/src/popup.js @@ -80,7 +80,7 @@ function updateNextEvent(nextEvents) { strongElement.textContent = browser.i18n.getMessage('noEventsInNext4Weeks'); calendarElement.append(strongElement); } else { - const nextEventDate = nextEvents[0].begin.substr(0, 10); + const nextEventDate = nextEvents[0].begin.substring(0, 10); const nextEventDateEvents = nextEvents.filter((nextEvent) => (nextEvent.begin.startsWith(nextEventDate))); nextEventDateEvents.forEach((nextEventDateEvent) => {