Search code examples
wso2try-catchsendwso2-esb

How can i catch error in wso2esb, when i send message to web service?


I have REST service, which return error http 500 (specially). Fault sequence not catch this error. How to catch this error? Thanks!

my config:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="d"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
         <send>
            <endpoint>
               <address uri="http://localhost:8080/rest/ris/b"/>
            </endpoint>
         </send>
         <log level="full"/>
      </inSequence>
      <outSequence>
         <send/>
         <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
         <log level="full"/>
      </outSequence>
      <faultSequence>
         <log level="full">
            <property name="MSG" value="==== FAULT CREATED ==="/>
         </log>
         <send/>
      </faultSequence>
   </target>
   <description/>
</proxy>

Solution

  • In your outSequence, when you receive a response from your REST service, you can test HTTP Status code with swith or filter mediator, sample :

    <filter source="$axis2:HTTP_SC" regex="500">
       <then>
          ...
       </then>
       <else>
          ...
       </else>
    </filter>