From a0ff17df96131a475734302b8e7e5b6814529597 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 29 Mar 2023 16:08:25 -0700 Subject: [PATCH] api: remove undefined in API.Q Signed-off-by: Varun Patil --- src/services/API.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/services/API.ts b/src/services/API.ts index a47e2558..e93b5557 100644 --- a/src/services/API.ts +++ b/src/services/API.ts @@ -43,10 +43,20 @@ export class API { ) { if (!query) return url; + if (typeof query === "object") { + // Clean up undefined and null + Object.keys(query).forEach((key) => { + if (query[key] === undefined || query[key] === null) { + delete query[key]; + } + }); + + // Convert to search params + query = new URLSearchParams(query); + } + if (query instanceof URLSearchParams) { query = query.toString(); - } else if (typeof query === "object") { - query = new URLSearchParams(query as any).toString(); } if (!query) return url;