How to gracefully fail an automatic token refresh

Jeroen H 40 Reputation points
2025-01-09T09:43:43.33+00:00

Hi all,

I'm using the CallClient from @azure/communication-calling to pick up on and add functionality to incoming Teams calls for users. When creating the teams CallClient, a 'tokenRefresher' can be assigned which periodically calls the method you assign to it. The method has token refresh logic to keep the CallClient working.

With my token refresh method, it is possible that a new token cannot be generated and no token can be returned. This will cause an ugly error in the tokenRefresher itself, and I fear it may crash my application at some point. Because the tokenRefresher is called outside of my managed code, I also can't add any error handling for it.

Is there a way to gracefully fail the tokenRefresher? From what I could tell the documentation recommends to return 'undefined' when no token can be refreshed. However, this still results in a 'Uncaught (in promise) InvalidTokenError: Invalid token specified: must be a string' error which I can't handle.

I understand that there is an abortSingal parameter that I can use, but this only helps with signaling new behavior outside the tokenRefresher, while I want the tokenRefresher itself to abort without error.

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
980 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,512 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.