Handling Error in MuleSoft Composer

Handling Error in MuleSoft Composer


Till now the biggest concern of every Mulesoft composer developer is how we can handle errors in composer flows. So, Now wait is over for handling errors in the composer is live now.

I have great news for you all. In this article I will go through the latest release of Mulesoft having new Actions for composer flow's i.e. THE ERROR HANDLER (Beta). With this we can handle errors for composer flows.

Error Handler (Beta) is available irrespective whether Mulesoft composer is standalone or it in is managed packages under Salesforce Orgs.



No alt text provided for this image
Error Handler (Beta)



Let's see, What’s New

An error handler (beta) is now available. You can use this feature to track down connection or error causes at certain steps of your flow, and then share the reasons to fix any problems that may occur.


And there are also a lot more updates for errors in the HTTP Connector in Mulesoft Composer.

  1. Error messages on HTTP connections now show different types of errors. When you complete the value field in the.
  2. REST client connection, the error specifying the value will no longer occur.
  3. Client Security now correctly validates the values provided in the Client Secret and Client ID fields when using API sharing.


The Error Handler component consists of 2 blocks.

No alt text provided for this image
Components of Error Handler (Beta)

1. Watch

The Watch block contains all possible component that may through error in flows.

2. On Error

The On error block only works if an component in the Watch block throws an error. Then you can handle all those errors in On Error block.



  • Depending on the configuration of the error handler component, the Key handler stops or aborts the flow when the item that occurs after the error handler is not executed in the block that generated the error. continue even if the error is thrown.
  • The Error handler (Beta) block works in a similar manner as Mulesoft error handling mechanism "on error propagate" and "on error continue".


For example

  • If you want to terminate the process as soon as the error is caught, here we have an option called "Stop". After selecting this in composer. Flow gets terminated with failed status in overview just like on error propagate.

No alt text provided for this image

  • But if you don't want this to happen you can select "Continue", this will help complete the process after having error with success status in overview just like on error continue.


There are some key best practices that we can take care while handling errors in Mulesoft composer.


Always trying to create errors in such a way that consist of accurate execution.
Put a generic error code at the end of all the different On Errors.
Add every possible component in the watch block that may throw errors.



Let's see with a use-case

In this use case, I will simply inserting the error logs in the same custom object for which the flow is triggered by record inserted or updated with the help of Error Handler (Beta).


Step 1.

  • Create a composer flow(with any option like System Event / Scheduler).
  • Here I am selecting On New or updated record in Salesforce and choosing New record.

No alt text provided for this image

Step 2.

  • Select your desired system event component. i.e. here this flow picks the records form trigger and inserting the some of fields by doing some operation using custom expression.

No alt text provided for this image

Step 3.

  • Insert Error Handler Beta.

Step 4.

  • Wrap all possible components in Error Handler.
  • Here I am wrapping my salesforce action in Error Watch.

No alt text provided for this image

Step 5.

  • Now you can handle your error by logging or exporting the error response ( as per your requirement).
  • In my case, I am exporting the error logs in a custom field called Description of the same custom object.

No alt text provided for this image

Step 6.

  • Save the flow / Start Testing it.
  • Here, I am testing by putting “Composer Name’ of length more than 2 so that it gives me an error.
  • As expected got this error - SALESFORCE:FAULTY_RESPONSE++ ":" ++ The attempted operation failed. Error detail: ## STRING_TOO_LONG- After test: data value too large: Demo-5 Start test (max length=2)

No alt text provided for this image

Step 7.

  • See the responses.

Anshuman Singh

Integration Engineer at NTT DATA Company ||3X Mulesoft Certified Developer ||MIA | MCD L1 | MCD L2 ||

1 年

????

Doradla Venkata Sai Deep Chand

Looking for JOB CHANGE || Integration Engineer at NTT DATA || 3x Mulesoft Certified || MCD-01 || MCIA || MCD-02

1 年

#cfbr

要查看或添加评论,请登录

社区洞察

其他会员也浏览了