Below is my Get method of MVC Web Api RC.
public Employee Get(int id)
{
Employee emp= null;
//try getting the Employee with given id, if not found, gracefully return error message with notfound status
if (!_repository.TryGet(id, out emp))
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent("Sorry! no Employee found with id " + id),
ReasonPhrase = "Error"
});
return emp;
}
Here problem is that whenever an error is thrown "Sorry! no Employee found with id ", is just in a plane text format. However i wanted to set the format as per my current formatter. Like by default i have set XML formatter in my global.asax. So the error should be displayed in XML format. Something like :
<error>
<error>Sorry! no Employee found with id </error>
</error>
similarly for Json formatter. It should be :
[{"errror","Sorry! no Employee found with id"}]
Thanks in advance