This repository was archived by the owner on Jan 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,20 @@ function handleAuthResponse (data) {
133
133
return Promise . resolve ( data )
134
134
}
135
135
136
+ /**
137
+ * Attempt to parse response body as JSON, fall back to parsing as a query string.
138
+ *
139
+ * @param {String } body
140
+ * @return {Object }
141
+ */
142
+ function parseResponseBody ( body ) {
143
+ try {
144
+ return JSON . parse ( body )
145
+ } catch ( e ) {
146
+ return Querystring . parse ( body )
147
+ }
148
+ }
149
+
136
150
/**
137
151
* Sanitize the scopes option to be a string.
138
152
*
@@ -266,16 +280,10 @@ ClientOAuth2.prototype._request = function (options) {
266
280
if ( res . status < 200 || res . status >= 399 ) {
267
281
var err = new Error ( 'HTTP status ' + res . status )
268
282
err . status = res . status
269
- err . body = res . body
283
+ err . body = parseResponseBody ( res . body )
270
284
return Promise . reject ( err )
271
285
}
272
-
273
- // Attempt to parse as JSON, fall back to parsing as a query string.
274
- try {
275
- return JSON . parse ( res . body )
276
- } catch ( e ) {
277
- return Querystring . parse ( res . body )
278
- }
286
+ return parseResponseBody ( res . body )
279
287
} )
280
288
}
281
289
You can’t perform that action at this time.
0 commit comments