Skip to content

Commit

Permalink
feat: handle 204 No Content gracefully (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Oct 19, 2023
1 parent cf70dea commit 2dd005c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
return Stream.fromSSEResponse(response, props.controller) as any;
}

// fetch refuses to read the body when the status code is 204.
if (response.status === 204) {
return null as T;
}

const contentType = response.headers.get('content-type');
if (contentType?.includes('application/json')) {
const json = await response.json();
Expand Down

0 comments on commit 2dd005c

Please sign in to comment.