Fix error when repository is null

This commit is contained in:
nemunaire 2022-09-16 12:02:47 +02:00
parent 99d58f69c2
commit 5940f14474

View File

@ -96,7 +96,12 @@ export async function getRemoteRepositories(userid) {
export async function getRepositories(wid, userid) { export async function getRepositories(wid, userid) {
const res = await fetch(userid?`api/users/${userid}/works/${wid}/repositories`:`api/works/${wid}/repositories`, {headers: {'Accept': 'application/json'}}) const res = await fetch(userid?`api/users/${userid}/works/${wid}/repositories`:`api/works/${wid}/repositories`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).map((r) => new WorkRepository(r)); const data = await res.json()
if (data) {
return data.map((r) => new WorkRepository(r));
} else {
return [];
}
} else { } else {
throw new Error((await res.json()).errmsg); throw new Error((await res.json()).errmsg);
} }