Skip to content

Commit f2e702e

Browse files
author
jwngr
committed
Handle getToken() being rejected with a non-Error type
It’s possible a user could provide a string type error (instead of an actual Error object) when defining a custom Credential.getAccessToken() method, and we should be able handle that case. Change-Id: Ib1d800584466a1b44093131d36a250ce2bc9a701
1 parent 5f9b2b1 commit f2e702e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/firebase-app.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ export class FirebaseAppInternals {
9898
this.cachedTokenPromise_ = null;
9999
}
100100

101-
let errorMessage = 'Credential implementation provided to initializeApp() via the ' +
101+
let errorMessage = (typeof error === 'string') ? error : error.message;
102+
103+
errorMessage = 'Credential implementation provided to initializeApp() via the ' +
102104
'"credential" property failed to fetch a valid Google OAuth2 access token with the ' +
103-
`following error: "${error.message}".`;
105+
`following error: "${errorMessage}".`;
104106

105-
if (error.message.indexOf('invalid_grant') !== -1) {
107+
if (errorMessage.indexOf('invalid_grant') !== -1) {
106108
errorMessage += ' There are two likely causes: (1) your server time is not properly ' +
107109
'synced or (2) your certificate key file has been revoked. To solve (1), re-sync the ' +
108110
'time on your server. To solve (2), make sure the key ID for your key file is still ' +

0 commit comments

Comments
 (0)