【发布时间】:2020-09-25 16:09:50
【问题描述】:
检查对 Cosmos DB 的调用是成功还是失败的最佳方法是什么?我应该检查响应中的状态代码还是捕获异常或两者兼而有之?有没有响应状态码不成功,但没有抛出异常的情况?
ContainerResponse containerResponse = null;
try
{
containerResponse = await cosmosClient.GetContainer(databaseId, containerId).ReadContainerAsync();
if (containerResponse.StatusCode != HttpStatusCode.Ok)
{
// the call failed. do something here.
}
}
catch (CosmosException ex) when (ex.StatusCode != HttpStatusCode.NotFound)
{
throw;
}
...
【问题讨论】:
标签: azure-cosmosdb