Skip to content

Commit d50a216

Browse files
committed
feat(client): allow binary returns (#416)
1 parent 647a417 commit d50a216

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/core.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
5252
return null as T;
5353
}
5454

55+
if (props.options.__binaryResponse) {
56+
return response as unknown as T;
57+
}
58+
5559
const contentType = response.headers.get('content-type');
5660
if (contentType?.includes('application/json')) {
5761
const json = await response.json();
@@ -61,10 +65,11 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
6165
return json as T;
6266
}
6367

64-
// TODO handle blob, arraybuffer, other content types, etc.
6568
const text = await response.text();
6669
debug('response', response.status, response.url, response.headers, text);
67-
return text as any as T;
70+
71+
// TODO handle blob, arraybuffer, other content types, etc.
72+
return text as unknown as T;
6873
}
6974

7075
/**
@@ -729,6 +734,8 @@ export type RequestOptions<Req extends {} = Record<string, unknown> | Readable>
729734
httpAgent?: Agent;
730735
signal?: AbortSignal | undefined | null;
731736
idempotencyKey?: string;
737+
738+
__binaryResponse?: boolean | undefined;
732739
};
733740

734741
// This is required so that we can determine if a given object matches the RequestOptions
@@ -747,6 +754,8 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
747754
httpAgent: true,
748755
signal: true,
749756
idempotencyKey: true,
757+
758+
__binaryResponse: true,
750759
};
751760

752761
export const isRequestOptions = (obj: unknown): obj is RequestOptions<Record<string, unknown> | Readable> => {

0 commit comments

Comments
 (0)