Makes sure it do not crashes when polling.

This commit is contained in:
2023-09-21 11:21:26 +02:00
parent 3311594f1e
commit 93b663c2c8
5 changed files with 23 additions and 14 deletions

View File

@@ -11,10 +11,16 @@ function isPromise(p: any): boolean {
async function pollGeneric(upstream: ServiceData, url: string): Promise<ServiceData> {
upstream.status = undefined;
return fetch(url).then((resp: Response): ServiceData => {
upstream.status = resp.ok ? 'online' : 'offline';
return upstream;
});
return fetch(url)
.then((resp: Response): ServiceData => {
upstream.status = resp.ok ? 'online' : 'offline';
return upstream;
})
.catch((error) => {
console.warn("could not fetch status for '" + url + "': " + error);
upstream.status = 'offline';
return upstream;
});
}
function wrapHandler(handler: ServiceHandler): AsyncServiceHandler {
@@ -55,6 +61,9 @@ export function initializeServiceData() {
serviceData.length = config.services.length;
for (let i = 0; i < serviceData.length; i++) {
serviceData[i] = [];
for (let j = 0; j < config.services[i].items.length; j++) {
serviceData[i][j] = {};
}
}
}