Add fetcher_helper for calendar and newsfeed

This commit is contained in:
rejas
2021-03-28 14:17:03 +02:00
committed by veeck
parent a6879e853b
commit 90aa50bb11
7 changed files with 31 additions and 21 deletions

View File

@@ -5,6 +5,7 @@
* MIT Licensed.
*/
const CalendarUtils = require("./calendarutils");
const FetcherHelper = require("fetcher_helper");
const Log = require("logger");
const ical = require("node-ical");
const fetch = require("node-fetch");
@@ -62,17 +63,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
}
fetcher
.catch((error) => {
fetchFailedCallback(this, error);
scheduleTimer();
})
.then((response) => {
if (response.status !== 200) {
fetchFailedCallback(this, response.statusText);
scheduleTimer();
}
return response;
})
.then(FetcherHelper.checkStatus)
.then((response) => response.text())
.then((responseData) => {
let data = [];
@@ -93,6 +84,10 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
}
this.broadcastEvents();
scheduleTimer();
})
.catch((error) => {
fetchFailedCallback(this, error.message);
scheduleTimer();
});
};