Skip to content

Commit 4a36f58

Browse files
chore(client): do not parse responses with empty content-length
1 parent b59ae98 commit 4a36f58

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/internal/parse.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export async function defaultParseResponse<T>(client: Together, props: APIRespon
4343
const mediaType = contentType?.split(';')[0]?.trim();
4444
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
4545
if (isJSON) {
46+
const contentLength = response.headers.get('content-length');
47+
if (contentLength === '0') {
48+
// if there is no content we can't do anything
49+
return undefined as T;
50+
}
51+
4652
const json = await response.json();
4753
return json as T;
4854
}

0 commit comments

Comments
 (0)