1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Fix error handling in mainpage and stats.

This commit is contained in:
Juliusz Chroboczek 2021-05-17 14:43:57 +02:00
parent 91fa693709
commit 781bdf8c74
2 changed files with 14 additions and 5 deletions

View file

@ -33,10 +33,15 @@ async function listPublicGroups() {
let l; let l;
try { try {
l = await (await fetch('/public-groups.json')).json(); let r = await fetch('/public-groups.json');
if(!r.ok)
throw new Error(`${r.status} ${r.statusText}`);
l = await r.json();
} catch(e) { } catch(e) {
console.error(e); table.textContent = `Couldn't fetch groups: ${e}`;
l = []; div.classList.remove('nogroups');
div.classList.add('groups');
return;
} }
if (l.length === 0) { if (l.length === 0) {

View file

@ -25,10 +25,14 @@ async function listStats() {
let l; let l;
try { try {
l = await (await fetch('/stats.json')).json(); let r = await fetch('/stats.json');
if(!r.ok)
throw new Error(`${r.status} ${r.statusText}`);
l = await r.json();
} catch(e) { } catch(e) {
console.error(e); console.error(e);
l = []; table.textContent = `Couldn't fetch stats: ${e}`;
return;
} }
if(l.length === 0) { if(l.length === 0) {