Layer7 API Management

Expand all | Collapse all

Catch the soap fault and error response before it is returned

Jump to Best Answer
  • 1.  Catch the soap fault and error response before it is returned

    Posted 06-24-2016 05:04 AM

    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??



  • 2.  Re: Catch the soap fault and error response before it is returned

    Posted 06-24-2016 08:10 AM

    Hi res13,

              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-

    Capture_Test_Service.PNG

    Thanks,

    Abhishek



  • 3.  Re: Catch the soap fault and error response before it is returned

    Posted 06-24-2016 09:00 AM

    Hi Abhishek

     

    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...



  • 4.  Re: Catch the soap fault and error response before it is returned
    Best Answer

    Posted 06-24-2016 10:52 AM

    Hi res13,

                 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,

    1. Instead of hard coding the response in the Return Template Response assertion, one can set the error information in a context variable & use them in the Return Template Response assertion.
    2. Please add a check after Route Assertion to to find if there was an error.
    3. In case there was an error, add logic to go to the database
    4. Once your DB logic is done, invoke Raise Error Assertion

     

    Thanks,

    Abhishek