I would like to return an HTTP status code & error message from a PUT method of an ApiController.
I have created an error class:
public class ErrorInformation
{
public string Message { get; set; }
public DateTime ErrorDate { get; set; }
}
and in the Put method I return this:
return new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.NotModified,
new ErrorInformation { Message = "We apologize but an unexpected error occured. Please try again later.", ErrorDate = DateTime.UtcNow }));
When the status code is, say:
HttpStatusCode.OK
or HttpStatusCode.InternalServerError
- the caller gets the object in the response. But when it is HttpStatusCode.NotModified
- only the status code is returned.
Why is this - and how can I ensure both my object and the status code are always returned?
thx.