Skip to content

Commit

Permalink
Fix getting JSON response for 204 status code (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbie committed Jun 4, 2024
1 parent 7c7269c commit f7fd387
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/slack/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit f7fd387

Please sign in to comment.