Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting JSON response for 204 status code #53

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

mbie marked this conversation as resolved.
Show resolved Hide resolved
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
kml marked this conversation as resolved.
Show resolved Hide resolved
}
catch (err) {
if (err.name === 'AbortError') {
Expand Down