I'm developing an API consuming Dynamics CRM through Microsoft.PowerPlatform.Dataverse.Client.
When invoking ExecuteAsync on the ServiceClient I would like to catch when there's an issue with the used JWT token.
I've been reading up on the documentation but seems to be no specific error related to this.
ChatGPT suggests this setup (simplified below), but can't find any proof of it in any documentation.
catch (FaultException<OrganizationServiceFault> ex)
{
var message = ex.Message.Contains("jwt", StringComparison.OrdinalIgnoreCase)
? "Request failed because of JWT exception."
: "Request failed.";
logger.LogError(ex, message, requestType.Name);
}
How could this be solved in a controlled and structured way?
ExpiredSecurityTokenExceptionit statesException thrown when a CardSpace security token expires..ServiceClientinstance token issues can be expected. Normally we do not need to catch authentication errors when invoking common Dataverse requests.