File tree Expand file tree Collapse file tree 2 files changed +133
-36
lines changed Expand file tree Collapse file tree 2 files changed +133
-36
lines changed Original file line number Diff line number Diff line change @@ -283,22 +283,23 @@ export abstract class HTTPDataSource<TContext = any> extends DataSource {
283283 signal : request . signal ,
284284 } )
285285
286- responseData . body . setEncoding ( 'utf8' )
287286 let data = ''
288287 for await ( const chunk of responseData . body ) {
289288 data += chunk
290289 }
291290
292- let json
293- if ( data ) {
294- json = sjson . parse ( data )
291+ let json = null
292+ if ( responseData . headers [ 'content-type' ] ?. includes ( 'application/json' ) ) {
293+ if ( data !== '' ) {
294+ json = sjson . parse ( data )
295+ }
295296 }
296297
297298 const response : Response < TResult > = {
298299 isFromCache : false ,
299300 memoized : false ,
300301 ...responseData ,
301- body : json ,
302+ body : json ?? data ,
302303 }
303304
304305 this . onResponse < TResult > ( request , response )
You can’t perform that action at this time.
0 commit comments