@@ -52,6 +52,10 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
52
52
return null as T ;
53
53
}
54
54
55
+ if ( props . options . __binaryResponse ) {
56
+ return response as unknown as T ;
57
+ }
58
+
55
59
const contentType = response . headers . get ( 'content-type' ) ;
56
60
if ( contentType ?. includes ( 'application/json' ) ) {
57
61
const json = await response . json ( ) ;
@@ -61,10 +65,11 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
61
65
return json as T ;
62
66
}
63
67
64
- // TODO handle blob, arraybuffer, other content types, etc.
65
68
const text = await response . text ( ) ;
66
69
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 ;
68
73
}
69
74
70
75
/**
@@ -729,6 +734,8 @@ export type RequestOptions<Req extends {} = Record<string, unknown> | Readable>
729
734
httpAgent ?: Agent ;
730
735
signal ?: AbortSignal | undefined | null ;
731
736
idempotencyKey ?: string ;
737
+
738
+ __binaryResponse ?: boolean | undefined ;
732
739
} ;
733
740
734
741
// This is required so that we can determine if a given object matches the RequestOptions
@@ -747,6 +754,8 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
747
754
httpAgent : true ,
748
755
signal : true ,
749
756
idempotencyKey : true ,
757
+
758
+ __binaryResponse : true ,
750
759
} ;
751
760
752
761
export const isRequestOptions = ( obj : unknown ) : obj is RequestOptions < Record < string , unknown > | Readable > => {
0 commit comments