Fix unhandled promise rejection warnings when access token refreshing fails
This commit is contained in:
parent
9e4313c416
commit
6d5fec23e2
|
@ -111,16 +111,17 @@ function refreshAccessToken(user, localRealmPath, realmUrl) {
|
|||
print_error(`Unhandled session token refresh error: could not look up session at path ${localRealmPath}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((e) => print_error(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* The base authentication method. It fires a JSON POST to the server parameter plus the auth url
|
||||
* For example, if the server parameter is `http://myapp.com`, this url will post to `http://myapp.com/auth`
|
||||
* @param {object} userConstructor
|
||||
* @param {string} server the http or https server url
|
||||
* @param {object} userConstructor
|
||||
* @param {string} server the http or https server url
|
||||
* @param {object} json the json to post to the auth endpoint
|
||||
* @param {Function} callback an optional callback with an error and user parameter
|
||||
* @param {Function} callback an optional callback with an error and user parameter
|
||||
* @returns {Promise} only returns a promise if the callback parameter was omitted
|
||||
*/
|
||||
function _authenticate(userConstructor, server, json, callback) {
|
||||
|
@ -149,8 +150,8 @@ function _authenticate(userConstructor, server, json, callback) {
|
|||
});
|
||||
|
||||
if (callback) {
|
||||
promise.then(user => {
|
||||
callback(null, user);
|
||||
promise.then(user => {
|
||||
callback(null, user);
|
||||
})
|
||||
.catch(err => {
|
||||
callback(err);
|
||||
|
@ -189,12 +190,12 @@ const staticMethods = {
|
|||
user_info: { password: password, register: true },
|
||||
data: username
|
||||
};
|
||||
|
||||
|
||||
if (callback) {
|
||||
const message = "register(..., callback) is now deprecated in favor of register(): Promise<User>. This function argument will be removed in future versions.";
|
||||
(console.warn || console.log).call(console, message);
|
||||
}
|
||||
|
||||
|
||||
return _authenticate(this, server, json, callback);
|
||||
},
|
||||
|
||||
|
@ -205,7 +206,7 @@ const staticMethods = {
|
|||
user_info: { password: password },
|
||||
data: username
|
||||
};
|
||||
|
||||
|
||||
if (callback) {
|
||||
const message = "login(..., callback) is now deprecated in favor of login(): Promise<User>. This function argument will be removed in future versions.";
|
||||
(console.warn || console.log).call(console, message);
|
||||
|
@ -216,7 +217,7 @@ const staticMethods = {
|
|||
|
||||
registerWithProvider(server, options, callback) {
|
||||
|
||||
// Compatibility with previous signature:
|
||||
// Compatibility with previous signature:
|
||||
// registerWithProvider(server, provider, providerToken, callback)
|
||||
if (arguments.length === 4) {
|
||||
checkTypes(arguments, ['string', 'string', 'string', 'function']);
|
||||
|
@ -242,7 +243,7 @@ const staticMethods = {
|
|||
const message = "registerWithProvider(..., callback) is now deprecated in favor of registerWithProvider(): Promise<User>. This function argument will be removed in future versions.";
|
||||
(console.warn || console.log).call(console, message);
|
||||
}
|
||||
|
||||
|
||||
return _authenticate(this, server, json, callback);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue