0
votes

An outgoing HTTP endpoint in my flow returns status 500, but Mule throws NO exception. When i step debug the flow, there is clearly an exception payload present after HTTP call, but the flow marches through to the end:

<flow name="pocFlow2" doc:name="pocFlow2">
    <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" path="poc/error" doc:name="HTTP"/>
    <!-- This one returns 500 error -->
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/>
    <object-to-string-transformer doc:name="Object to String"/>
    <set-payload value="All good" doc:name="Set Payload"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <logger level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</flow>

Is this expected behavior? Do i have to throw the error myself after every HTTP call?

1

1 Answers

0
votes

Yes, you need to check the status code of the response and take whatever action is appropriate. Mule doesn't know what call you are making or what status code you are expecting, so the http connector doesn't throw the exception. One of the little annoying things about Mule is that there isn't a simple way to throw an exception. I've written a very simple little ExceptionThrower java class to handle this case.

    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties['http.status'] == '200']">
            <!-- Handle my payload -->
        </when>
        <otherwise>
            <!-- This isn't what I expected, so throw an exception to let the catch-exception-strategy handle it. -->
            <component class="com.example.ExceptionThrower" doc:name="Java"/>
        </otherwise>
    </choice>