Hello @Jeroen H, To gracefully handle the failure of the tokenRefresher
in the CallClient
from @azure/communication-calling
, you can implement a safeguard within your token refresh method to ensure that it does not return an invalid token or undefined
. Instead, you can handle the error internally and return a valid token or a fallback mechanism.
Here is an example of how you can implement such a safeguard in your token refresh method:
async function tokenRefresher() {
try {
// Replace this with your actual token refresh logic
const newToken = await refreshToken();
if (newToken) {
return newToken;
} else {
// Handle the case where no new token is generated
console.warn("Failed to refresh token. Returning a placeholder token.");
return "placeholder-token"; // Use a valid placeholder token or handle accordingly
}
} catch (error) {
console.error("Error refreshing token:", error);
// Return a valid placeholder token or handle the error gracefully
return "placeholder-token";
}
}
// Initialize CallClient with the tokenRefresher
const callClient = new CallClient({
tokenRefresher: tokenRefresher,
// other parameters
});