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,9 +11,15 @@ export const handle: ServiceHandler = async (config: ServiceConfig) => {
config.url + '/api.php?summaryRaw&auth=' + config.api_token
);
res.status = resp.ok ? 'online' : 'offline';
res.raw = resp.json();
const raw = await resp.json();
res.data = {
queries_today: raw.dns_queries_today,
ads_percentage: raw.ads_percentage_today,
status: raw.status,
client: raw.unique_clients
};
} catch (error) {
res.status = undefined;
res.status = 'offline';
console.warn('could not fetch pihole status: ' + error);
}