Reuse and add to 500 error to get better stats fro

2019-08-15 12:01发布

问题:

We deliver a huge amount of data based on soap requests. Whenever a request fails, soap specifies a 500 error must be returned with a response object telling about the error. Now I know for a fact that MANY of our responses actually should be 400 errors due to bad requests, but we are not allowed to send those. Is it possible to add something to the http log files for the 500 "I am not really a 500" errors to be picked up by Analog or other stats?

Thanks

回答1:

If you are using Apache you could use a custom log format and add a field such as:

%{Foobar}o

Where "Foobar" is the name of a header you send back in the response. Then all you need to do is add a custom header in the error response to indicate it was due to bad user input. Just be sure to start your custom header name with "X-" so that it is valid (i.e. X-Foobar)

See the mod_log_config documentation for more information about custom log formats.