Skip to content

Commit c494aed

Browse files
chore(client): do not parse responses with empty content-length
1 parent aaa02d0 commit c494aed

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/core.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
7070
const mediaType = contentType?.split(';')[0]?.trim();
7171
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
7272
if (isJSON) {
73+
const contentLength = response.headers.get('content-length');
74+
if (contentLength === '0') {
75+
// if there is no content we can't do anything
76+
return undefined as T;
77+
}
78+
7379
const json = await response.json();
7480

7581
debug('response', response.status, response.url, response.headers, json);

0 commit comments

Comments
 (0)