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 2727
2828/**
2929 * The supported formats for the returned OAuth2 token.
30- * @type {Object.<string, string>
30+ * @type {Object.<string, string> }
3131 */
3232var TOKEN_FORMAT = {
3333 JSON : 'application/json' ,
@@ -65,7 +65,7 @@ function getRedirectUri(scriptId) {
6565 return Utilities . formatString ( 'https://script.google.com/macros/d/%s/usercallback' , scriptId ) ;
6666}
6767
68- if ( module ) {
68+ if ( typeof module === 'object' ) {
6969 module . exports = {
7070 createService : createService ,
7171 getRedirectUri : getRedirectUri
@@ -466,7 +466,8 @@ Service_.prototype.getRedirectUri = function() {
466466 */
467467Service_ . prototype . getTokenFromResponse_ = function ( response ) {
468468 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 ) {
470471 var reason = [
471472 token . error ,
472473 token . message ,
@@ -476,7 +477,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
476477 return typeof ( part ) == 'string' ? part : JSON . stringify ( part ) ;
477478 } ) . join ( ', ' ) ;
478479 if ( ! reason ) {
479- reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
480+ reason = resCode + ': ' + JSON . stringify ( token ) ;
480481 }
481482 throw 'Error retrieving token: ' + reason ;
482483 }
Original file line number Diff line number Diff line change @@ -392,7 +392,8 @@ Service_.prototype.getRedirectUri = function() {
392392 */
393393Service_ . prototype . getTokenFromResponse_ = function ( response ) {
394394 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 ) {
396397 var reason = [
397398 token . error ,
398399 token . message ,
@@ -402,7 +403,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
402403 return typeof ( part ) == 'string' ? part : JSON . stringify ( part ) ;
403404 } ) . join ( ', ' ) ;
404405 if ( ! reason ) {
405- reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
406+ reason = resCode + ': ' + JSON . stringify ( token ) ;
406407 }
407408 throw 'Error retrieving token: ' + reason ;
408409 }
You can’t perform that action at this time.
0 commit comments