For returning from a Web API 2 controller, I can return content with the response if the response is OK (status 200) like this:
public IHttpActionResult
For exceptions, I usually do
catch (Exception ex)
{
return InternalServerError(new ApplicationException("Something went wrong in this request. internal exception: " + ex.Message));
}
Anyone who is interested in returning anything with any statuscode with returning ResponseMessage:
//CreateResponse(HttpStatusCode, T value)
return ResponseMessage(Request.CreateResponse(HttpStatusCode.XX, object));
Simple:
return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Your message"));
Remember to reference System.Net.Http and System.Net.