title: WSO2 ESB does not return error code in case of endpoint failure
body: <p>I have a proxy service in WSO2 ESB which is listening over a Queue via JMS and then after some processing it sends message to another queue. It works fine. I am implementing fault sequence of this service that in case if endpoint is suspended then it should send message to an error queue. In fault sequence WSO2 ESB is generating ERROR_MESSAGE, ERROR_DETAIL, ERROR_EXCEPTION but it is not generating ERROR_CODE. </p>
  
  <p><strong>Fault Sequence:</strong></p>
  
  <pre><code>&lt;faultSequence xmlns="http://ws.apache.org/ns/synapse"&gt;
     &lt;log level="full" separator="**********Fault Sequence File Processor***********"&gt;
        &lt;property name="ErrorCode" expression="get-property('ERROR_CODE')"&gt;&lt;/property&gt;
        &lt;property name="ErrorMessage" expression="get-property('ERROR_MESSAGE')"&gt;&lt;/property&gt;
        &lt;property name="ErrorDetail" expression="get-property('ERROR_DETAIL')"&gt;&lt;/property&gt;
        &lt;property name="ErrrorException" expression="get-property('ERROR_EXCEPTION')"&gt;&lt;/property&gt;
     &lt;/log&gt;
     &lt;payloadFactory media-type="xml"&gt;
        &lt;format&gt;
           &lt;MessageFormat xmlns=""&gt;
              &lt;ECode&gt;$1&lt;/ECode&gt;
              &lt;EMsg&gt;$2&lt;/EMsg&gt;
              &lt;EDetail&gt;$3&lt;/EDetail&gt;
              &lt;EException&gt;$4&lt;/EException&gt;
           &lt;/MessageFormat&gt;
        &lt;/format&gt;
        &lt;args&gt;
           &lt;arg expression="get-property('ERROR_CODE')" evaluator="xml"&gt;&lt;/arg&gt;
           &lt;arg expression="get-property('ERROR_MESSAGE')" evaluator="xml"&gt;&lt;/arg&gt;
           &lt;arg expression="get-property('ERROR_DETAIL')" evaluator="xml"&gt;&lt;/arg&gt;
           &lt;arg expression="get-property('ERROR_EXCEPTION')" evaluator="xml"&gt;&lt;/arg&gt;
        &lt;/args&gt;
     &lt;/payloadFactory&gt;
     &lt;property name="OUT_ONLY" value="true" scope="default" type="STRING"&gt;&lt;/property&gt;
     &lt;property name="ClientApiNonBlocking" action="remove" scope="axis2"&gt;&lt;/property&gt;
     &lt;send&gt;
        &lt;endpoint key="conf:/endpoints/ErrorQueue.xml"&gt;&lt;/endpoint&gt;
     &lt;/send&gt;
  &lt;/faultSequence&gt;
  </code></pre>
  
  <p><strong>Endpoint Which i am suspending:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;endpoint xmlns="http://ws.apache.org/ns/synapse" name="Endpoint"&gt;
      &lt;address uri="jms:/RequestQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://192.168.1.33:61616&amp;amp;transport.jms.DestinationType=queue" format="pox"&gt;
  &lt;timeout&gt;
              &lt;duration&gt;6000&lt;/duration&gt;
          &lt;/timeout&gt;
  
          &lt;markForSuspension&gt;
              &lt;errorCodes&gt;101504, 101505, 303001, 303000&lt;/errorCodes&gt;
              &lt;retriesBeforeSuspension&gt;1&lt;/retriesBeforeSuspension&gt;
              &lt;retryDelay&gt;1&lt;/retryDelay&gt;
          &lt;/markForSuspension&gt;
  
          &lt;suspendOnFailure&gt;
              &lt;errorCodes&gt;101500, 101501, 101506, 101507, 101508, 303001, 303000&lt;/errorCodes&gt;
              &lt;initialDuration&gt;1000&lt;/initialDuration&gt;
              &lt;progressionFactor&gt;2&lt;/progressionFactor&gt;
              &lt;maximumDuration&gt;6400&lt;/maximumDuration&gt;
          &lt;/suspendOnFailure&gt;
  
  
  &lt;/address&gt;
  
  
  &lt;/endpoint&gt;
  </code></pre>
  
  <p><strong>Note:</strong>
  The <strong>IP</strong> mentioned in the <strong>"address"</strong> URI is not correct so that's why service goes into fault sequence. </p>
  
  <p><strong>Output on Error Queue:</strong></p>
  
  <pre><code>&lt;MessageFormat&gt;&lt;ECode&gt;0&lt;/ECode&gt;&lt;EMsg&gt;Unexpected error during sending message out&lt;/EMsg&gt;&lt;EDetail&gt;org.apache.synapse.SynapseException: Unexpected error during sending message out
          at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:172)
          at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:71)
          at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:338)
          at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:333)
          at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
          at org.apache.synapse.endpoints.IndirectEndpoint.send(IndirectEndpoint.java:54)
          at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:97)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
          at org.apache.synapse.mediators.eip.Target.mediate(Target.java:106)
          at org.apache.synapse.mediators.eip.splitter.IterateMediator.mediate(IterateMediator.java:146)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
          at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
          at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
          at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
          at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
          at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
          at org.apache.synapse.transport.vfs.VFSTransportListener.processFile(VFSTransportListener.java:597)
          at org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory(VFSTransportListener.java:328)
          at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:158)
          at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:107)
          at org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run(AbstractPollingTransportListener.java:67)
          at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
          at java.lang.Thread.run(Thread.java:744)
  Caused by: org.apache.axis2.AxisFault: Unable to create a JMSMessageSender for : null
          at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:226)
          at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:129)
          at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
          at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
          at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
          at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
          at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
          at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
          ... 33 more
  Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://192.168.1.33:61616. Reason: java.net.NoRouteToHostException: No route to host
          at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
          at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:301)
          at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:246)
          at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:203)
          at org.apache.axis2.transport.jms.JMSOutTransportInfo.createJMSSender(JMSOutTransportInfo.java:363)
          at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:127)
          ... 39 more
  &lt;/EDetail&gt;&lt;EException&gt;&lt;/EException&gt;&lt;/MessageFormat&gt;
  </code></pre>
  
  <p><strong>Problem:</strong>
  Why WSO2 ESB does not generate ERROR_CODE? I have to get that error code and on the basis of error code make some further logic. </p>