File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 27
27
28
28
/**
29
29
* The supported formats for the returned OAuth2 token.
30
- * @type {Object.<string, string>
30
+ * @type {Object.<string, string> }
31
31
*/
32
32
var TOKEN_FORMAT = {
33
33
JSON : 'application/json' ,
@@ -65,7 +65,7 @@ function getRedirectUri(scriptId) {
65
65
return Utilities . formatString ( 'https://script.google.com/macros/d/%s/usercallback' , scriptId ) ;
66
66
}
67
67
68
- if ( module ) {
68
+ if ( typeof module === 'object' ) {
69
69
module . exports = {
70
70
createService : createService ,
71
71
getRedirectUri : getRedirectUri
@@ -466,7 +466,8 @@ Service_.prototype.getRedirectUri = function() {
466
466
*/
467
467
Service_ . prototype . getTokenFromResponse_ = function ( response ) {
468
468
var token = this . parseToken_ ( response . getContentText ( ) ) ;
469
- if ( response . getResponseCode ( ) != 200 || token . error ) {
469
+ var resCode = response . getResponseCode ( ) ;
470
+ if ( ! ( resCode >= 200 && resCode < 300 ) || token . error ) {
470
471
var reason = [
471
472
token . error ,
472
473
token . message ,
@@ -476,7 +477,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
476
477
return typeof ( part ) == 'string' ? part : JSON . stringify ( part ) ;
477
478
} ) . join ( ', ' ) ;
478
479
if ( ! reason ) {
479
- reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
480
+ reason = resCode + ': ' + JSON . stringify ( token ) ;
480
481
}
481
482
throw 'Error retrieving token: ' + reason ;
482
483
}
Original file line number Diff line number Diff line change @@ -392,7 +392,8 @@ Service_.prototype.getRedirectUri = function() {
392
392
*/
393
393
Service_ . prototype . getTokenFromResponse_ = function ( response ) {
394
394
var token = this . parseToken_ ( response . getContentText ( ) ) ;
395
- if ( response . getResponseCode ( ) != 200 || token . error ) {
395
+ var resCode = response . getResponseCode ( ) ;
396
+ if ( resCode < 200 || resCode >= 300 || token . error ) {
396
397
var reason = [
397
398
token . error ,
398
399
token . message ,
@@ -402,7 +403,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
402
403
return typeof ( part ) == 'string' ? part : JSON . stringify ( part ) ;
403
404
} ) . join ( ', ' ) ;
404
405
if ( ! reason ) {
405
- reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
406
+ reason = resCode + ': ' + JSON . stringify ( token ) ;
406
407
}
407
408
throw 'Error retrieving token: ' + reason ;
408
409
}
You can’t perform that action at this time.
0 commit comments