File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -507,7 +507,10 @@ var Client = module.exports = function(config) {
507507
508508 var ret ;
509509 try {
510- ret = res . data && JSON . parse ( res . data ) ;
510+ ret = res . data ;
511+ var contentType = res . headers [ "content-type" ] ;
512+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
513+ ret = JSON . parse ( ret ) ;
511514 }
512515 catch ( ex ) {
513516 if ( callback )
@@ -517,12 +520,14 @@ var Client = module.exports = function(config) {
517520
518521 if ( ! ret )
519522 ret = { } ;
520- if ( ! ret . meta )
521- ret . meta = { } ;
522- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "link" ] . forEach ( function ( header ) {
523- if ( res . headers [ header ] )
524- ret . meta [ header ] = res . headers [ header ] ;
525- } ) ;
523+ if ( typeof ret == "object" ) {
524+ if ( ! ret . meta )
525+ ret . meta = { } ;
526+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "link" ] . forEach ( function ( header ) {
527+ if ( res . headers [ header ] )
528+ ret . meta [ header ] = res . headers [ header ] ;
529+ } ) ;
530+ }
526531
527532 if ( callback )
528533 callback ( null , ret ) ;
You can’t perform that action at this time.
0 commit comments