Handle refresh errors by re-authenticating

This commit is contained in:
Matt Low 2021-03-14 12:16:59 -06:00
parent ac30269c81
commit d9ac440498

View File

@ -68,20 +68,24 @@ async function initRingCentralSDK() {
clientId: process.env.RC_APP_KEY, clientId: process.env.RC_APP_KEY,
clientSecret: process.env.RC_APP_SECRET, clientSecret: process.env.RC_APP_SECRET,
}); });
const platform = sdk.platform();
platform.on(platform.events.refreshError, (err) => { const login = () =>
console.error("Refresh error", err); sdk.login({
});
const client = sdk.client();
client.on(client.events.beforeRequest, (request) => {
console.log(request.url);
});
await sdk.login({
username: process.env.RC_LOGIN_USERNAME, username: process.env.RC_LOGIN_USERNAME,
extension: process.env.RC_LOGIN_EXT, extension: process.env.RC_LOGIN_EXT,
password: process.env.RC_LOGIN_PASSWORD, password: process.env.RC_LOGIN_PASSWORD,
}); });
const platform = sdk.platform();
platform.on(platform.events.refreshError, async (err) => {
console.error("Refresh token error:", err);
await login();
console.log("RingCentral re-authentication successful.");
});
await login();
console.log("Authenticated to RingCentral."); console.log("Authenticated to RingCentral.");
return sdk; return sdk;
} }