我正在使用带有 Blazor WebAssembly(客户端)的 Azure CosmosDB。
我想在连接令牌过期时捕获 CosmosException,但没有得到 cosmos 异常,(发现空异常)
我还在控制台应用程序中尝试了相同的代码,因为我能够捕获显示令牌已过期的 cosmos 异常。
代码示例:
using (CosmosClient client = new CosmosClient(account, token))
{
Database db = null;
db = client.GetDatabase("databaseName");
Container orgContainer = client.GetContainer("databaseName","containerName");
try
{
ItemResponse<CosmosException> response = await orgContainer.ReadItemAsync<CosmosException>("test", new PartitionKey("test"));
var data = response.Resource;
}
catch(CosmosException ex)
{
}
catch(Exception ex)
{
}
}