We would like to log the soap fault (for published web services) and the error response (for published rest services) before it is returned back to the requestor. In the service policy we have a lot of "Customize SOAP Fault Response" or "Customize Error Response" assertions which override the default error response while a service policy is running. At the end of each service policy we perform a log to an external database. This log must be done before the error is thrown back to the requestor, therefore the content of the error is not yet in the response message.
Is there any possibility to get the error message which will be returned to the requestor, before it is thrown, so we can log what really goes back??
Please check if you have the assertion - Raise Error under Policy Logic. We can use it to invoke error at any point in the policy. Please do make sure to add logic not mix up the error due to DB write which you are planning to do. I have attached a simple snapshot to help you understand easily-
I think you did not understand what I am trying to do. In your snapshot there is a comment which says "Add assertions to log into external database" and after that "Raise Error". And what I try to achieve is to log the content of the raise error assertion (error message, http error status) before it is thrown instead of logging the response message from the "route via https assertion".
Because in case of an error, of course the error will be given back to the user (which is right) but in our logs we do not have exactly what was given back to the user...
Got you issue. The Template response is only a potential response until there is error. As a workaround, you to use the same steps I have put in the previous reply. Additionally,