Handle case when there is no Action nor Routine
This commit is contained in:
parent
6956cf3b96
commit
8ebeb11b74
@ -50,7 +50,12 @@ export class Action {
|
|||||||
export async function getActions() {
|
export async function getActions() {
|
||||||
const res = await fetch(`api/actions`, {headers: {'Accept': 'application/json'}})
|
const res = await fetch(`api/actions`, {headers: {'Accept': 'application/json'}})
|
||||||
if (res.status == 200) {
|
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 {
|
} else {
|
||||||
throw new Error((await res.json()).errmsg);
|
throw new Error((await res.json()).errmsg);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,12 @@ export class Routine {
|
|||||||
export async function getRoutines() {
|
export async function getRoutines() {
|
||||||
const res = await fetch(`api/routines`, {headers: {'Accept': 'application/json'}})
|
const res = await fetch(`api/routines`, {headers: {'Accept': 'application/json'}})
|
||||||
if (res.status == 200) {
|
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 {
|
} else {
|
||||||
throw new Error((await res.json()).errmsg);
|
throw new Error((await res.json()).errmsg);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user