ravi
ravi

Reputation: 23

WSO2 ESB: How to handle internal error returned by an endpoint

I am using CALL mediator to invoke a Get method on an endpoint. The endpoint returns 500 internal server error as pasted below. But instead of control going to the fault sequence, the mediation flow continues as usual. How to route to fault sequence? How to handle internal error in wso2?

[2020-02-14 17:51:21,175] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << HTTP/1.1 500 Internal Server Error
[2020-02-14 17:51:21,175] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << HTTP/1.1 500 Internal Server Error
[2020-02-14 17:51:21,176] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Strict-Transport-Security: max-age=15638400; includeSubDomains
[2020-02-14 17:51:21,176] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Strict-Transport-Security: max-age=15638400; includeSubDomains
[2020-02-14 17:51:21,177] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Access-Control-Allow-Methods: POST, GET
[2020-02-14 17:51:21,177] DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Access-Control-Allow-Methods: POST, GET

Upvotes: 0

Views: 1017

Answers (1)

Arunan
Arunan

Reputation: 3459

WSO2 ESB does not hit fault sequence when the endpoint returns 500 because, irrespective of the response code, the mediation flow should proceed. We can retrieve the status code of the response and then trigger the fault sequence. A sample insequence is given below.

<inSequence>
     <call>
        <endpoint>
           <http uri-template="http://www.mocky.io/v2/5e465018330000520002605f"/>
        </endpoint>
     </call>
     <filter source="$axis2:HTTP_SC" regex="500">
        <then>
           <sequence key="fault"/>
        </then>
        <else/>
     </filter>
     <respond/>
  </inSequence>

Upvotes: 1

Related Questions