Implementing a Choice Exception Strategy icon

Implementing a Choice Exception Strategy

(0 reviews)

home

Illustrates the concept of error handling in Mule. This particular example deals with choice exception strategy.

Example

JSON sales data is sent through the HTTP endpoint. The input data is validated and in case of missing or invalid data, an appropriate exception is thrown. A series of custom filters then catch the exception in the JSON data and route the message to the error handling flow. The input data is validated and in case of missing or invalid data, an appropriate exception is thrown.

Set Up and Run the Example

  1. Run the example project as a Mule application

  2. Use Postman to make the following JSON POST request:

     {
     "email": "aaa@aaa.aa",
     "item name": "aa",
     "item units": 10,
     "item price per unit": 1,
     "membership": "free"
     }

    This message throws no error and returns the following messsage:

     Input data validation passed.
  3. Use Postman to make the following JSON POST request:

     {
     "item name": "aa",
     "item units": 10,
     "item price per unit": 1,
     "membership": "free"
     }

    This message throws an exception as the email field is missing. Status code 400 is returned with the following message:

     Missing input data: {item name=aa, membership=free, item price per unit=1, item units=10}
  4. Use Postman to make the following JSON POST request:

     {
     "email": "aaa@aaa.aa",
     "item name": "aa",
     "item units": 10,
     "item price per unit": -1,
     "membership": "free"
     }

This message throws an exception as the item price per unit is negative, and the following error message is returned. This applies to negative item units as well.

   Invalid input data: {item name=aa, membership=free, item price per unit=-1, email=aaa@aaa.aa, item units=10}

Documentation

Read full documentation in GitHub

Examples to Try Next

If you understood this example
Import Contacts Into Salesforce - Learn how to take a CSV file of contacts and upload them to Salesforce.View
If you struggled with this example
Content Based Routing - Learn how to route messages based on the logic you supply in the Choice Router.View
Filtering a Message - Learn how to use filter components to filter an incoming message.View

Reviews

TypeExample
OrganizationMulesoft
Published by
MuleSoft Organization
Published onJun 14, 2019
Asset overview

Asset versions for 1.4.x

Asset versions
VersionActions
1.4.0