【发布时间】:2016-08-03 23:31:52
【问题描述】:
我的控制器中有这段代码:
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new Exception("Your cat is too small"));
在我的调用代码中,我想检索异常或至少是错误。我写了这段代码:
ObjectContent objContent = response.Content as ObjectContent;
objContent 的类型是 HttpError,所以我把它拿出来了:
HttpError error = objContent.Value as HttpError;
但error 似乎是一个字典,只有一个值,key: Message, ValueL "An error has occurred"
我看不到任何异常迹象。
Assert.AreEqual("Your cat is too small", error["Message"]);
断言失败。
【问题讨论】:
-
HttpError具有属性ExceptionMessage和InnerException。有人住吗? -
怕不是,都是
null
标签: c# asp.net-web-api