I am building a REST API using .net WEB API.
Here is a sample code
public class ValuesController : ApiController
{
// GET api/values
public Values Get(int ID, int userID)
{
return new Values(){};
}
}
Now what I want to do is return a different class if userID is not in allowed userID list. I was thinking of throwing an exception, but after I considered it I don't think that would be a good idea. Reason for this is that process was handled with OK status.
Basically I would like to return a custom ErrorMessage object instead of Values object. Is it possible to do it?
throw new HttpResponseException(HttpStatusCode.NotFound);? This is equivalent to a 404 response.Reason for this is that process was handled with OK status.meanthrow new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound){ReasonPhrase = "Couldn't locate userID"});