Answered by:
What sense in HttpResponseException

Question
-
User3112162 posted
Why is it necessary?
The following 2 methods return the same response.
[Route("Get1")] [HttpGet] public HttpResponseMessage Get1() { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("ABC"), ReasonPhrase = "phrase" }; throw new HttpResponseException(resp); } [Route("Get3")] [HttpGet] public HttpResponseMessage Get3() { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("ABC"), ReasonPhrase = "phrase" }; return resp; }
Saturday, March 19, 2016 10:06 PM
Answers
-
User36583972 posted
Hi rover83
1: HttpResponseException
What happens if a Web API controller throws an uncaught exception? By default, most exceptions are translated into an HTTP response with status code 500, Internal Server Error. The HttpResponseException type is a special case. This exception returns any HTTP status code that you specify in the exception constructor.
So, HttpResponseException is necessary. You can refer the following tutorial for getting more information.
Exception Handling in ASP.NET Web API:
http://www.asp.net/web-api/overview/error-handling/exception-handling
2: HttpResponseMessage
A HttpResponseMessage allows us to work with the HTTP protocol and unifies our return type. In simple words an HttpResponseMessage is a way of returning a message/data from your action.
http://www.c-sharpcorner.com/UploadFile/036f9e/httpresponsemessage-in-webapi166/
3: The difference between HttpResponseMessage and HttpResponseException in the below for your reference.
Best Regards,
Yohann Lu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 21, 2016 5:18 AM
All replies
-
User-252718598 posted
Did the datagrams responsed have any difference? use the fiddler to catch.
Monday, March 21, 2016 1:38 AM -
User36583972 posted
Hi rover83
1: HttpResponseException
What happens if a Web API controller throws an uncaught exception? By default, most exceptions are translated into an HTTP response with status code 500, Internal Server Error. The HttpResponseException type is a special case. This exception returns any HTTP status code that you specify in the exception constructor.
So, HttpResponseException is necessary. You can refer the following tutorial for getting more information.
Exception Handling in ASP.NET Web API:
http://www.asp.net/web-api/overview/error-handling/exception-handling
2: HttpResponseMessage
A HttpResponseMessage allows us to work with the HTTP protocol and unifies our return type. In simple words an HttpResponseMessage is a way of returning a message/data from your action.
http://www.c-sharpcorner.com/UploadFile/036f9e/httpresponsemessage-in-webapi166/
3: The difference between HttpResponseMessage and HttpResponseException in the below for your reference.
Best Regards,
Yohann Lu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 21, 2016 5:18 AM