Skip to content

Commit 2e677a5

Browse files
authored
Merge pull request #45 from aniongithub/fix/empty-wiki
fix: guard API client against null JSON responses for empty wiki
2 parents 35d925d + 559d79e commit 2e677a5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

webui/src/mcp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class APIClient {
3939
const url = prefix ? `/api/pages?prefix=${encodeURIComponent(prefix)}` : '/api/pages';
4040
const res = await fetch(url);
4141
if (!res.ok) throw new Error(`HTTP ${res.status}`);
42-
return res.json();
42+
return (await res.json()) || [];
4343
}
4444

4545
async searchPages(query: string, limit = 20): Promise<SearchResult[]> {
4646
const res = await fetch(`/api/search?q=${encodeURIComponent(query)}&limit=${limit}`);
4747
if (!res.ok) throw new Error(`HTTP ${res.status}`);
48-
return res.json();
48+
return (await res.json()) || [];
4949
}
5050

5151
async createPage(path: string, content: string): Promise<void> {
@@ -74,7 +74,7 @@ class APIClient {
7474
async getBacklinks(path: string): Promise<string[]> {
7575
const res = await fetch(`/api/backlinks/${path}`);
7676
if (!res.ok) throw new Error(`HTTP ${res.status}`);
77-
return res.json();
77+
return (await res.json()) || [];
7878
}
7979

8080
async allLinks(): Promise<Link[]> {

0 commit comments

Comments
 (0)