@@ -73,7 +73,7 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
73
73
} ;
74
74
75
75
/**
76
- * Sets the additional HTTP headers that should be sent when retrieving or
76
+ * Sets the additional HTTP headers that should be sent when retrieving or
77
77
* refreshing the access token.
78
78
* @param Object.<string,string> tokenHeaders A map of header names to values.
79
79
* @return {Service_ } This service, for chaining.
@@ -197,7 +197,7 @@ Service_.prototype.setPrivateKey = function(privateKey) {
197
197
} ;
198
198
199
199
/**
200
- * Sets the issuer (iss) value to use for Service Account authorization.
200
+ * Sets the issuer (iss) value to use for Service Account authorization.
201
201
* If not set the client ID will be used instead.
202
202
* @param {string } issuer This issuer value
203
203
* @return {Service_ } This service, for chaining.
@@ -208,7 +208,7 @@ Service_.prototype.setIssuer = function(issuer) {
208
208
} ;
209
209
210
210
/**
211
- * Sets the subject (sub) value to use for Service Account authorization.
211
+ * Sets the subject (sub) value to use for Service Account authorization.
212
212
* @param {string } subject This subject value
213
213
* @return {Service_ } This service, for chaining.
214
214
*/
@@ -301,7 +301,10 @@ Service_.prototype.handleCallback = function(callbackRequest) {
301
301
} ) ;
302
302
var token = this . parseToken_ ( response . getContentText ( ) ) ;
303
303
if ( response . getResponseCode ( ) != 200 ) {
304
- var reason = token . error ? token . error : response . getResponseCode ( ) ;
304
+ var reason = token . error ;
305
+ if ( ! reason ) {
306
+ reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
307
+ }
305
308
throw 'Error retrieving token: ' + reason ;
306
309
}
307
310
this . saveToken_ ( token ) ;
@@ -431,8 +434,11 @@ Service_.prototype.refresh = function() {
431
434
} ) ;
432
435
var newToken = this . parseToken_ ( response . getContentText ( ) ) ;
433
436
if ( response . getResponseCode ( ) != 200 ) {
434
- var reason = newToken . error ? newToken . error : response . getResponseCode ( ) ;
435
- throw 'Error refreshing token: ' + reason ;
437
+ var reason = newToken . error ;
438
+ if ( ! reason ) {
439
+ reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( newToken ) ;
440
+ }
441
+ throw 'Error retrieving token: ' + reason ;
436
442
}
437
443
if ( ! newToken . refresh_token ) {
438
444
newToken . refresh_token = token . refresh_token ;
@@ -537,7 +543,10 @@ Service_.prototype.exchangeJwt_ = function() {
537
543
} ) ;
538
544
var token = this . parseToken_ ( response . getContentText ( ) ) ;
539
545
if ( response . getResponseCode ( ) != 200 ) {
540
- var reason = token . error ? token . error : response . getResponseCode ( ) ;
546
+ var reason = token . error ;
547
+ if ( ! reason ) {
548
+ reason = response . getResponseCode ( ) + ': ' + JSON . stringify ( token ) ;
549
+ }
541
550
throw 'Error retrieving token: ' + reason ;
542
551
}
543
552
this . saveToken_ ( token ) ;
@@ -577,4 +586,4 @@ Service_.prototype.createJwt_ = function() {
577
586
var signatureBytes = Utilities . computeRsaSha256Signature ( toSign , this . privateKey_ ) ;
578
587
var signature = Utilities . base64EncodeWebSafe ( signatureBytes ) ;
579
588
return toSign + '.' + signature ;
580
- } ;
589
+ } ;
0 commit comments