Implementing a Choice Exception Strategy icon

Implementing a Choice Exception Strategy

(0 reviews)

home

Understand the concept of error handling in Mule using a choice exception strategy.


Screenshot of the main flow in Anypoint Studio, view full image here

Description

This example illustrates the concept of error handling in mule. This particular example deals with choice exception strategy.

Example use case

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 22, 2017
Asset overview

Asset versions for 1.1.x

Asset versions
VersionActions
1.1.0