DocumentClientException.Error.Code 可以有哪些值?
Which values can DocumentClientException.Error.Code have?
我希望我的数据访问层能够处理由 Microsoft.Azure.Documents.Client.DocumentClient
class 提供的 DocumentDB API 抛出的异常。例如,使用 AccessCondition class 实现的乐观并发检查,但其他的也是如此。
通过查看抛出的异常,识别不同 DocumentClient
特定异常的最佳方法似乎是这样的:
try { ... }
catch (DocumentClientException exception)
when (exception.Error.Code == "Some magic here")
{
//let the user know how to recover from this..
}
我不喜欢这种神奇的字符串,因为它们在编译时不可验证。它可能会出现打字错误,或者它可能会随着 DocumentDB client/server 的变化而随机变化,等等。此外,我还不清楚我 could/should 正在处理哪些魔术代码,因为我没有看到 Microsoft.Azure.DocumentDB
.net API 包含任何 ErrorCodes
枚举或常量,也没有在文档中找到任何列表。
在哪里可以找到 DocumentClient API 可以抛出的 Error.Code
可能值的列表?
为了让它更加混乱,DocumentClient.CreateDocumentAsync
方法的 XmlDoc 建议改为处理 http 状态代码。
更新: 这个问题不是关于 Http 状态代码,而是关于 DocumentClientException.Error.Code
字段,因为我认为后者更精确。
有一个列表 HTTP Status Codes for Azure Cosmos DB
我在 catch 块中使用了以下代码
catch (DocumentClientException e)
{
var resp = new HttpResponseMessage
{
StatusCode = (HttpStatusCode) e.StatusCode,
Content = new StringContent(e.Message)
};
return resp;
}
让用户知道如何处理异常应该在客户端应用程序上完成。
Where can I find a list of possible error codes values DocumentClient API can throw?
很难找到 DocumentClinet API 抛出的完整错误代码列表。例外取决于您的要求。
For example, the optimistic concurrency check
Azure Cosmos DB 使用 ETags 来处理开放式并发。
当我们从 Azure Cosmos DB 检索文档时,它始终包含一个 ETag 属性 作为我们文档的一部分。
当我们随后想要发送替换文档的请求时,我们可以使用提取文档时收到的 ETag 指定 AccessCondition。
如果我们发送的 ETag 不是最新的,服务器将 return 一个 412 Precondition Failed 状态代码 。在我们的 .NET SDK 中,这包含在 DocumentClientException.
中
这里有一个example显示并发时可能出现的问题。
通过反编译1.22.0版客户端,代码被设置为HttpStatusCode枚举。我认为所有可能的值都可以在这里找到 https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx 那么。
然而,真正包含更丰富调试信息的是Error.Message。可能需要反编译整个库才能弄清楚,或者等待微软发布源代码,这不太可能发生,因为 github 的最新更新是 2 或 3 年前。
public Error Error
{
get
{
if (this.error == null)
{
this.error = new Error()
{
Code = this.StatusCode.ToString(),
Message = this.Message
};
}
return this.error;
}
}
我希望我的数据访问层能够处理由 Microsoft.Azure.Documents.Client.DocumentClient
class 提供的 DocumentDB API 抛出的异常。例如,使用 AccessCondition class 实现的乐观并发检查,但其他的也是如此。
通过查看抛出的异常,识别不同 DocumentClient
特定异常的最佳方法似乎是这样的:
try { ... }
catch (DocumentClientException exception)
when (exception.Error.Code == "Some magic here")
{
//let the user know how to recover from this..
}
我不喜欢这种神奇的字符串,因为它们在编译时不可验证。它可能会出现打字错误,或者它可能会随着 DocumentDB client/server 的变化而随机变化,等等。此外,我还不清楚我 could/should 正在处理哪些魔术代码,因为我没有看到 Microsoft.Azure.DocumentDB
.net API 包含任何 ErrorCodes
枚举或常量,也没有在文档中找到任何列表。
在哪里可以找到 DocumentClient API 可以抛出的 Error.Code
可能值的列表?
为了让它更加混乱,DocumentClient.CreateDocumentAsync
方法的 XmlDoc 建议改为处理 http 状态代码。
更新: 这个问题不是关于 Http 状态代码,而是关于 DocumentClientException.Error.Code
字段,因为我认为后者更精确。
有一个列表 HTTP Status Codes for Azure Cosmos DB
我在 catch 块中使用了以下代码
catch (DocumentClientException e)
{
var resp = new HttpResponseMessage
{
StatusCode = (HttpStatusCode) e.StatusCode,
Content = new StringContent(e.Message)
};
return resp;
}
让用户知道如何处理异常应该在客户端应用程序上完成。
Where can I find a list of possible error codes values DocumentClient API can throw?
很难找到 DocumentClinet API 抛出的完整错误代码列表。例外取决于您的要求。
For example, the optimistic concurrency check
Azure Cosmos DB 使用 ETags 来处理开放式并发。
当我们从 Azure Cosmos DB 检索文档时,它始终包含一个 ETag 属性 作为我们文档的一部分。
当我们随后想要发送替换文档的请求时,我们可以使用提取文档时收到的 ETag 指定 AccessCondition。
如果我们发送的 ETag 不是最新的,服务器将 return 一个 412 Precondition Failed 状态代码 。在我们的 .NET SDK 中,这包含在 DocumentClientException.
中这里有一个example显示并发时可能出现的问题。
通过反编译1.22.0版客户端,代码被设置为HttpStatusCode枚举。我认为所有可能的值都可以在这里找到 https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx 那么。
然而,真正包含更丰富调试信息的是Error.Message。可能需要反编译整个库才能弄清楚,或者等待微软发布源代码,这不太可能发生,因为 github 的最新更新是 2 或 3 年前。
public Error Error
{
get
{
if (this.error == null)
{
this.error = new Error()
{
Code = this.StatusCode.ToString(),
Message = this.Message
};
}
return this.error;
}
}