Skip to content

Commit c7d08f2

Browse files
committed
fix(null-statuses): empty bodies handling
1 parent 103b31a commit c7d08f2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

apps/sim/tools/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,22 @@ async function executeToolRequest(
643643
})
644644

645645
const responseHeaders = new Headers(secureResponse.headers.toRecord())
646-
const bodyBuffer = await secureResponse.arrayBuffer()
646+
const nullBodyStatuses = new Set([101, 204, 205, 304])
647647

648-
response = new Response(bodyBuffer, {
649-
status: secureResponse.status,
650-
statusText: secureResponse.statusText,
651-
headers: responseHeaders,
652-
})
648+
if (nullBodyStatuses.has(secureResponse.status)) {
649+
response = new Response(null, {
650+
status: secureResponse.status,
651+
statusText: secureResponse.statusText,
652+
headers: responseHeaders,
653+
})
654+
} else {
655+
const bodyBuffer = await secureResponse.arrayBuffer()
656+
response = new Response(bodyBuffer, {
657+
status: secureResponse.status,
658+
statusText: secureResponse.statusText,
659+
headers: responseHeaders,
660+
})
661+
}
653662
}
654663

655664
// For non-OK responses, attempt JSON first; if parsing fails, fall back to text
@@ -693,11 +702,9 @@ async function executeToolRequest(
693702
throw errorToTransform
694703
}
695704

696-
// Parse response data once with guard for empty 202 bodies
697705
let responseData
698706
const status = response.status
699-
if (status === 202) {
700-
// Many APIs (e.g., Microsoft Graph) return 202 with empty body
707+
if (status === 202 || status === 204) {
701708
responseData = { status }
702709
} else {
703710
if (tool.transformResponse) {

0 commit comments

Comments
 (0)