From 8506beebe93c703d4e356201ecab4dd182c40750 Mon Sep 17 00:00:00 2001 From: Skillz Date: Wed, 15 Jul 2020 09:49:13 -0400 Subject: [PATCH] fix get methods with query params --- module/requestManager.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/module/requestManager.ts b/module/requestManager.ts index 354a6ed7e..64d721cff 100644 --- a/module/requestManager.ts +++ b/module/requestManager.ts @@ -90,6 +90,8 @@ function createRequestBody(body: any, method: RequestMethod) { "X-Audit-Log-Reason": body ? encodeURIComponent(body.reason) : "", }; + if (method === "get") body = undefined; + if (body?.file) { const form = new FormData(); form.append("file", body.file.blob, body.file.name); @@ -146,7 +148,15 @@ async function runMethod( ); } - const response = await fetch(url, createRequestBody(body, method)); + const query = method === "get" && body + ? Object.entries(body as any).map(([key, value]) => + `${encodeURIComponent(key)}=${encodeURIComponent(value as any)}` + ) + .join("&") + : ""; + const urlToUse = method === "get" && query ? `${url}?${query}` : url; + console.log("url thing", urlToUse); + const response = await fetch(urlToUse, createRequestBody(body, method)); const bucketIDFromHeaders = processHeaders(url, response.headers); handleStatusCode(response);