@@ -38,7 +38,10 @@ var authorization = module.exports = {
38
38
39
39
var ret ;
40
40
try {
41
- ret = res . data && JSON . parse ( res . data ) ;
41
+ ret = res . data ;
42
+ var contentType = res . headers [ "content-type" ] ;
43
+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
44
+ ret = JSON . parse ( ret ) ;
42
45
}
43
46
catch ( ex ) {
44
47
if ( callback )
@@ -48,12 +51,14 @@ var authorization = module.exports = {
48
51
49
52
if ( ! ret )
50
53
ret = { } ;
51
- if ( ! ret . meta )
52
- ret . meta = { } ;
53
- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
54
- if ( res . headers [ header ] )
55
- ret . meta [ header ] = res . headers [ header ] ;
56
- } ) ;
54
+ if ( typeof ret == "object" ) {
55
+ if ( ! ret . meta )
56
+ ret . meta = { } ;
57
+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
58
+ if ( res . headers [ header ] )
59
+ ret . meta [ header ] = res . headers [ header ] ;
60
+ } ) ;
61
+ }
57
62
58
63
if ( callback )
59
64
callback ( null , ret ) ;
@@ -78,7 +83,10 @@ var authorization = module.exports = {
78
83
79
84
var ret ;
80
85
try {
81
- ret = res . data && JSON . parse ( res . data ) ;
86
+ ret = res . data ;
87
+ var contentType = res . headers [ "content-type" ] ;
88
+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
89
+ ret = JSON . parse ( ret ) ;
82
90
}
83
91
catch ( ex ) {
84
92
if ( callback )
@@ -88,12 +96,14 @@ var authorization = module.exports = {
88
96
89
97
if ( ! ret )
90
98
ret = { } ;
91
- if ( ! ret . meta )
92
- ret . meta = { } ;
93
- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
94
- if ( res . headers [ header ] )
95
- ret . meta [ header ] = res . headers [ header ] ;
96
- } ) ;
99
+ if ( typeof ret == "object" ) {
100
+ if ( ! ret . meta )
101
+ ret . meta = { } ;
102
+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
103
+ if ( res . headers [ header ] )
104
+ ret . meta [ header ] = res . headers [ header ] ;
105
+ } ) ;
106
+ }
97
107
98
108
if ( callback )
99
109
callback ( null , ret ) ;
@@ -120,7 +130,10 @@ var authorization = module.exports = {
120
130
121
131
var ret ;
122
132
try {
123
- ret = res . data && JSON . parse ( res . data ) ;
133
+ ret = res . data ;
134
+ var contentType = res . headers [ "content-type" ] ;
135
+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
136
+ ret = JSON . parse ( ret ) ;
124
137
}
125
138
catch ( ex ) {
126
139
if ( callback )
@@ -130,12 +143,14 @@ var authorization = module.exports = {
130
143
131
144
if ( ! ret )
132
145
ret = { } ;
133
- if ( ! ret . meta )
134
- ret . meta = { } ;
135
- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
136
- if ( res . headers [ header ] )
137
- ret . meta [ header ] = res . headers [ header ] ;
138
- } ) ;
146
+ if ( typeof ret == "object" ) {
147
+ if ( ! ret . meta )
148
+ ret . meta = { } ;
149
+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
150
+ if ( res . headers [ header ] )
151
+ ret . meta [ header ] = res . headers [ header ] ;
152
+ } ) ;
153
+ }
139
154
140
155
if ( callback )
141
156
callback ( null , ret ) ;
@@ -165,7 +180,10 @@ var authorization = module.exports = {
165
180
166
181
var ret ;
167
182
try {
168
- ret = res . data && JSON . parse ( res . data ) ;
183
+ ret = res . data ;
184
+ var contentType = res . headers [ "content-type" ] ;
185
+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
186
+ ret = JSON . parse ( ret ) ;
169
187
}
170
188
catch ( ex ) {
171
189
if ( callback )
@@ -175,12 +193,14 @@ var authorization = module.exports = {
175
193
176
194
if ( ! ret )
177
195
ret = { } ;
178
- if ( ! ret . meta )
179
- ret . meta = { } ;
180
- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
181
- if ( res . headers [ header ] )
182
- ret . meta [ header ] = res . headers [ header ] ;
183
- } ) ;
196
+ if ( typeof ret == "object" ) {
197
+ if ( ! ret . meta )
198
+ ret . meta = { } ;
199
+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
200
+ if ( res . headers [ header ] )
201
+ ret . meta [ header ] = res . headers [ header ] ;
202
+ } ) ;
203
+ }
184
204
185
205
if ( callback )
186
206
callback ( null , ret ) ;
@@ -205,7 +225,10 @@ var authorization = module.exports = {
205
225
206
226
var ret ;
207
227
try {
208
- ret = res . data && JSON . parse ( res . data ) ;
228
+ ret = res . data ;
229
+ var contentType = res . headers [ "content-type" ] ;
230
+ if ( contentType && contentType . indexOf ( "application/json" ) !== - 1 )
231
+ ret = JSON . parse ( ret ) ;
209
232
}
210
233
catch ( ex ) {
211
234
if ( callback )
@@ -215,12 +238,14 @@ var authorization = module.exports = {
215
238
216
239
if ( ! ret )
217
240
ret = { } ;
218
- if ( ! ret . meta )
219
- ret . meta = { } ;
220
- [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
221
- if ( res . headers [ header ] )
222
- ret . meta [ header ] = res . headers [ header ] ;
223
- } ) ;
241
+ if ( typeof ret == "object" ) {
242
+ if ( ! ret . meta )
243
+ ret . meta = { } ;
244
+ [ "x-ratelimit-limit" , "x-ratelimit-remaining" , "x-ratelimit-reset" , "x-oauth-scopes" , "link" , "location" , "last-modified" , "etag" , "status" ] . forEach ( function ( header ) {
245
+ if ( res . headers [ header ] )
246
+ ret . meta [ header ] = res . headers [ header ] ;
247
+ } ) ;
248
+ }
224
249
225
250
if ( callback )
226
251
callback ( null , ret ) ;
0 commit comments