在我的DataService derrived类中,我已经覆盖了HandleException方法,以便进行自定义异常处理(简化示例):
protected override void HandleException(HandleExceptionArgs args)
{
args.Exception = new DataServiceException(
args.ResponseStatusCode,
"RecordAlreadyExist",
"The record with the given ID already exists in the database",
System.Globalization.CultureInfo.CurrentCulture.Name,
null);
base.HandleException(args);
}
这会导致类似以下JSON响应:
{
"error": {
"code": "RecordAlreadyExist",
"Message": {
"Language": "en-US",
"Message": "The record with the given ID already exists in the database"
}
}
}
但我希望在错误响应中有一些额外的信息,如:
{
"error": {
"code": "RecordAlreadyExist",
"Message": {
"Language": "en-US",
"Message": "The record with the given ID already exists in the database"
},
"RecordID": "1234"
}
}
我该怎么做? DataServiceException仅支持错误代码和消息...