Search code examples
mulemule-studioanypoint-studiomulesoft

how to handle http connector response code


Currently in mule, I have a flow process that makes an http connection to elasticsearch. We are using the scroll api and all connections are fine. I am trying to create a flow to handle the 404 status code which would be returned in the event that the scroll_id has expired on a request. At the moment, I added code 404 to the advanced settings for "Failure Status Code Validator" section on the http connector. What I want to accomplish is that when 404 is returned from this particular http call (which we know is due to the scroll_id expiry), we make another http call to another gateway. So when 404, make another http call to a separate link.

Thanks in advance. I am still learning the xml code, but if you have an anypoint studio experience in the GUI that would be extremely helpful.


Solution

  • I accomplished this by setting a success status code validator under the Advanced tab of the http-connector.

    Before setting this value, when getting a 404, the mulesoft would raise its default exception for error code 4xx. At the moment, I still can't figure out how to override that or set something additional, and that could be due to this particular project I am taking over. However, in the success code validator section, I set the values to 200,404 which is saying that a status code of 200 and 404 can pass to the next component in the flow. By default, if you don't set 404, again mulesoft will throw its default built in error message for status code 404. So since I am telling mulesoft to treat this as okay, I can pass to the next component in my project. At the next flow immediately after the outbound http call to an external rest service, I have a choice-component in place that is evaluating what the status code of the http call is. To do this, you can use this: #[message.inboundProperties.'http.status' == '404'] which is saying, use this particular flow path if the status code is 404, else use the default path.

    enter image description here