Handle case when there is no Action nor Routine

This commit is contained in:
nemunaire 2022-12-08 14:14:34 +01:00
parent 6956cf3b96
commit 8ebeb11b74
2 changed files with 12 additions and 2 deletions

View File

@ -50,7 +50,12 @@ export class Action {
export async function getActions() {
const res = await fetch(`api/actions`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return (await res.json()).map((t) => new Action(t));
const data = await res.json();
if (data == null) {
return []
} else {
return data.map((t) => new Action(t));
}
} else {
throw new Error((await res.json()).errmsg);
}

View File

@ -45,7 +45,12 @@ export class Routine {
export async function getRoutines() {
const res = await fetch(`api/routines`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return (await res.json()).map((r) => new Routine(r));
const data = await res.json();
if (data == null) {
return []
} else {
return data.map((r) => new Routine(r));
}
} else {
throw new Error((await res.json()).errmsg);
}