This project is read-only.

The original request in OnProvideResponse

Topics: Web Api
May 31, 2011 at 5:07 PM

Hi guys,

Could I get the original HttpRequestMessage as a parameter in OnProvideResponse?

I want to serialize an exception to the original requested format. So json when the Accept was application/json, xml for xml.

I don't have that info there. Or am I looking at it wrong?


Jun 8, 2011 at 12:09 PM

ehm ... pretty please with sugar on top?

Jun 9, 2011 at 2:08 PM

Not sure if this helps but HttpResponseException has a Response property of type HttpResponseMessage and HttpResponseMessage has a Request property of type HttpRequestMessage.  

e.g. var httpRequestMessage = exception.Response.Request;

Depending on where you throw the exception and who creates the HttpResponseMessage, that Request property may or may not be set.  If you are creating the exception and throwing it yourself, then you should be able to ensure that the Request property is set.