HttpResponseException

Viewed 22118

I am facing a big problem for handling errors in MVC 4 webAPI. Here I want to validate incoming request and send back a BadRequest response.

For that i am using the code

public Product GetProduct(int id)
{
    Product item = repository.Get(id);
   if (item == null)
   {
     throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
   }
   return item;
}

But In case of null id, VS2010 will produce another error like

"Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details".

How can i resolve this problem

Thanks in advance....

4 Answers
Related