From 5c8d4dd362fcc5e85c59e3b36ea7fbbcfcff6d9a Mon Sep 17 00:00:00 2001 From: Mateusz Bielec Date: Tue, 4 Jun 2024 12:55:27 +0200 Subject: [PATCH 1/2] Fix getting JSON response for 204 status code --- 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..d1ca295 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') { From 8ed2b8f5b4b6fea5b3f5135cf0c83e28129edfb5 Mon Sep 17 00:00:00 2001 From: Mateusz Bielec Date: Tue, 4 Jun 2024 13:44:15 +0200 Subject: [PATCH 2/2] Return {} instead of string --- packages/slack/src/request.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slack/src/request.ts b/packages/slack/src/request.ts index d1ca295..a35a56a 100644 --- a/packages/slack/src/request.ts +++ b/packages/slack/src/request.ts @@ -23,7 +23,7 @@ function sanitizeTimeout(timeout) { } function getJSON(response) { - if (response.status === 204) return ''; + if (response.status === 204) return {}; return response.json(); }