user3165854
user3165854

Reputation: 1655

How to get HTTP Status code from Mule application

I am using Anypoint Studio 6.1 and Mule 3.8.1 and have a flow that calls MongoDB. I want to see how to get the HTTP status so I can configure my exception handling. When I disconnect MongoDB and run the Mule workflow it fails as expected, but the HTTP status is returned as null when I try this expression message.inboundProperties['http.status'] and the exception message code is -1, but when I play the error through to the end of the workflow the status shows as 500 in Postman.

How can I get the HTTP status?

Thanks

Upvotes: 0

Views: 6610

Answers (2)

Abani Patra
Abani Patra

Reputation: 172

If you are using APIKit Router then you can use the following code:

 <apikit:mapping-exception-strategy name="apiKitGlobalExceptionMapping">
    <apikit:mapping statusCode="500">
         <apikit:exception value="java.lang.Exception"/>
         <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
         <set-payload value="{ &quot;message&quot;: &quot;Internal server error&quot; }" doc:name="Set Payload" />
     </apikit:mapping>

For more details you can check here

Upvotes: 0

Alagappan
Alagappan

Reputation: 66

message.inboundProperties['http.status'] will give the http.status code when a HTTP Request invocation is made within the flow. If the flow is trying to invoke DB, then you may need to have a catch exception strategy inside the error handling of the flow to catch the desired exception. If the exception is matched, you can set the http.status and exception payload to be sent to the client end.

Upvotes: 1

Related Questions