1

I've implemented logging of all requests/responses using (in my AppHost.cs):

this.RequestFilters.Add(serviceLogFilter.LogRequest);
this.ResponseFilters.Add(serviceLogFilter.LogResponse);

During the logging of the request, I get the new ID from the logging table and put it into IHttpRequest.Items.

My question is: when an error occurs, like if the validation of the incoming data fails, or my business logic throws an Exception, is there a way I can customize the returned error to contain my log reference? Preferably by adding a JSON body to the error response. Alternatively, setting a custom HTTP header?

The idea is that my customer could give me a log reference if something unexcpected happens, and I would find his request and could easily reproduce the problem.

Scott
  • 21,211
  • 8
  • 65
  • 72
Magge
  • 268
  • 2
  • 7

1 Answers1

0

See this question on different ways to Handle exceptions from the old and New API.

To use the IHttpRequest.Items dictionary to pass data between request filters, services and response filters in the same request.

Also the InMemoryRollingRequestLogger implementation for the Request Logger plugin shows another way to be able to log all requests.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • After investigating a bit more, a logging Filter (AppHost.ResponseFilters) will be run also when an Exception occurs in my Service. I can add a log ID there, so that part of the problem is solved. However for validation failures, which I'd also like to log, the response filter is NOT run. I tried creating a custom ServiceRunner but neither HandleException or AfterEachRequest is run when validation fails. – Magge Oct 26 '12 at 11:44