From f7fd38729bbbcb7c632c4265e247f00a18ba1725 Mon Sep 17 00:00:00 2001 From: Mateusz Bielec Date: Tue, 4 Jun 2024 13:46:24 +0200 Subject: [PATCH] Fix getting JSON response for 204 status code (#53) --- packages/slack/src/request.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/slack/src/request.ts b/packages/slack/src/request.ts index 93a871b..a35a56a 100644 --- a/packages/slack/src/request.ts +++ b/packages/slack/src/request.ts @@ -22,6 +22,11 @@ function sanitizeTimeout(timeout) { return undefined } +function getJSON(response) { + if (response.status === 204) return {}; + return response.json(); +} + class BadStatusCodeError extends Error { statusCode: number response: any @@ -68,7 +73,7 @@ async function request(method, { uri, headers, body, form, json, timeout }): Pro if (response.status >= 400) { throw new BadStatusCodeError(response) } - return json ? response.json() : response + return json ? getJSON(response) : response } catch (err) { if (err.name === 'AbortError') {