From 53ee9af8daac1bdca1db9ffcfe7cb8ae35606960 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:54:09 +0200 Subject: [PATCH 1/2] fix web api client --- web/src/lib/api/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/lib/api/client.ts b/web/src/lib/api/client.ts index 905119be451..c016cfdd83d 100644 --- a/web/src/lib/api/client.ts +++ b/web/src/lib/api/client.ts @@ -48,7 +48,7 @@ export default class ApiClient { ...(this.token !== null ? { Authorization: `Bearer ${this.token}` } : {}), ...(data !== undefined ? { 'Content-Type': 'application/json' } : {}), }, - body: data !== undefined ? JSON.stringify(data) : undefined, + body: data !== undefined && data !== null ? JSON.stringify(data) : undefined, }); if (!res.ok) { From 923a09b3d65b0e874fe4de163ebf6b5a5a2fba01 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:57:58 +0200 Subject: [PATCH 2/2] fix types --- web/src/lib/api/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/lib/api/client.ts b/web/src/lib/api/client.ts index c016cfdd83d..ca3d1dc89aa 100644 --- a/web/src/lib/api/client.ts +++ b/web/src/lib/api/client.ts @@ -40,7 +40,7 @@ export default class ApiClient { this.csrf = csrf; } - private async _request(method: string, path: string, data: unknown): Promise { + private async _request(method: string, path: string, data?: unknown): Promise { const res = await fetch(`${this.server}${path}`, { method, headers: { @@ -48,7 +48,7 @@ export default class ApiClient { ...(this.token !== null ? { Authorization: `Bearer ${this.token}` } : {}), ...(data !== undefined ? { 'Content-Type': 'application/json' } : {}), }, - body: data !== undefined && data !== null ? JSON.stringify(data) : undefined, + body: data !== undefined ? JSON.stringify(data) : undefined, }); if (!res.ok) { @@ -71,7 +71,7 @@ export default class ApiClient { } _get(path: string) { - return this._request('GET', path, null); + return this._request('GET', path); } _post(path: string, data?: unknown) { @@ -83,7 +83,7 @@ export default class ApiClient { } _delete(path: string) { - return this._request('DELETE', path, null); + return this._request('DELETE', path); } _subscribe(path: string, callback: (data: T) => void, opts = { reconnect: true }) {