Skip to content

Commit

Permalink
fix: improve response body check for node 16 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 23, 2023
1 parent c1f075f commit 64d3aed
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const retryStatusCodes = new Set([
504, // Gateway Timeout
]);

// https://developer.mozilla.org/en-US/docs/Web/API/Response/body
const nullBodyResponses = new Set([101, 204, 205, 304]);

export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
const {
fetch = globalThis.fetch,
Expand Down Expand Up @@ -222,7 +225,11 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
return await onError(context);
}

if (context.response.body) {
const hasBody =
context.response.body &&
!nullBodyResponses.has(context.response.status) &&
context.options.method !== "HEAD";
if (hasBody) {
const responseType =
(context.options.parseResponse
? "json"
Expand Down

0 comments on commit 64d3aed

Please sign in to comment.