我正在学习c#中的web api。我想知道如何捕捉从服务器端发送的响应对象的异常消息。在客户端捕获异常消息
假设这是服务器端抛出的响应异常消息。所以我如何在客户端捕获它。通过使用正常的尝试抓住它没有显示的消息。
try
{
}
catch{Exception exception)
{
var errorMessage = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(exception.Message) };
throw new HttpResponseException(errorMessage);
}
检查这个问题,你可能会得到一些线索。 http://stackoverflow.com/questions/12260300/throwing-httpresponseexception-in-webapi-action-method-returning-empty-200-respo – Vinod