Last post Mar 21, 2012 01:39 AM by Kiran Challa
Mar 20, 2012 10:09 PM|Kevin Burton|LINK
I have a Post method that has the following signature:
public HttpResponseMessage<SubmitFeedResponse> Post(AmazonEnvelope envelope)
In the body I would like to return an indication of an error if one occurs. So I have the following code:
HttpResponseMessage errorResponse = this.ControllerContext.Request.CreateResponse();
errorResponse.Content = new StringContent("No connection string");
return errorResponse as HttpResponseMessage<SubmitFeedResponse>;
But this only returns an empty SubmitFeedResponse object with no error and the string content is not set. In such a case how do I return an error? I could also just new an HttpResponseMessage<SubmitFeedResponse> but then I get a whole buch of errors basically
telling me I need to use CreateContent<SubmitFeedResponse> to create and ObjectContent<SubmitFeedResponse> but then I don't know where to put my error message (StringContent).
Mar 21, 2012 01:39 AM|Kiran Challa|LINK
You could throw HttpResponseException with the message in your controller. The messages thrown as part of these exceptions are sent back to the client in a content negotiated way.