我正在使用RESTier 0.6.0库,希望在删除资源之前对其执行一些检查。如果检查失败,我将抛出一个异常来停止删除操作。然而,我用来实例化异常的错误消息并没有在最高级别被推出。当从Visual Studio提供我的Web API时,我只能将该消息视为内部异常。有没有办法把这个错误消息推送到最高级别?
protected void OnDeletingGw_Pack(Gw_Pack pack)
{
var trades = ModelContext.Gw_PackJunction.Where(e => e.PackID == pack.PackID).ToList();
if (pack.Groupage == true || trades.Count > 1)
{
// Don't delete a pack if it is a groupage container or if it's associated with more than one Trade.
throw new Exception("The container you are trying to delete is either marked as groupage or is functioning as a groupage container in another file.");
}
}目前,在EntityFrameworkApi中的OnDelete提交逻辑方法中抛出的任何异常都会导致如下所示的错误:
{ " error ":{ "code":"",“message”:“发生错误”}}
..。这对客户端来说并不是特别有用。
更新:我在RESTier文档MkDocs version中注意到,给出了一个抛出ODataException (而不是异常)的示例。我在代码中对此进行了更改,但发布的Restier服务返回的error对象仍然只包含基本的“已发生错误”信息。
非常感谢您的帮助!
发布于 2017-04-19 22:21:18
当在RESTier EntityFrameworkApi中抛出异常(例如inside和OnUpdate<EntitySet>方法)时,该异常将被反序列化为内部异常(内部异常)的一部分。因此,为了查看RESTier应用程序接口中抛出的任何异常,需要...
在HttpConfiguration类上设置IncludeErrorDetailPolicy属性,如下所示:
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.AlwaysStructure of error received by client
请看这篇文章:OData controller returns different error for local and different for remote machine
https://stackoverflow.com/questions/42779451
复制相似问题