Skip to content

Commit 64d3aed

Browse files
committed
fix: improve response body check for node 16 compatibility
1 parent c1f075f commit 64d3aed

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/fetch.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ const retryStatusCodes = new Set([
9191
504, // Gateway Timeout
9292
]);
9393

94+
// https://developer.mozilla.org/en-US/docs/Web/API/Response/body
95+
const nullBodyResponses = new Set([101, 204, 205, 304]);
96+
9497
export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
9598
const {
9699
fetch = globalThis.fetch,
@@ -222,7 +225,11 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
222225
return await onError(context);
223226
}
224227

225-
if (context.response.body) {
228+
const hasBody =
229+
context.response.body &&
230+
!nullBodyResponses.has(context.response.status) &&
231+
context.options.method !== "HEAD";
232+
if (hasBody) {
226233
const responseType =
227234
(context.options.parseResponse
228235
? "json"

0 commit comments

Comments
 (0)