我想获得自动异常序列化,而无需手动将ResponseStatus添加到响应DTO。
根据有关未处理异常行为的this信息,我编写了以下代码
public class ContactService : RestServiceBase<Contact>
{
public override object OnGet(Contact request)
{
return ContactApi.GetContactInfo(request);
}
//To trigger the serialization of the Exception to ResponseStatus
protected override object HandleException(Contact request, Exception ex)
{
throw ex;
}
<snip />
}
您是否认为以这种方式使用库有任何问题?
提前致谢。
更新:我希望在出现异常时得到以下响应,而不必将ResponseStatus属性添加到我的响应DTO对象。
我可以通过重写HandleException方法来实现这一点,如上所示。
我的问题是: 能否以这种方式覆盖默认的异常处理行为会导致出现任何问题?
{
"ResponseStatus":{
"ErrorCode":"ApplicationException",
"Message":"CRASH",
}
}