Anypoint Exchange

Home to the complete listing of connectors, templates, examples and APIs.
Discover and use proven assets built by the MuleSoft ecosystem, or add assets to a private
tenant of Anypoint Exchange for collaboration and sharing of internal best practices.

Learn more
Sign up
Implementing a Choice Exception Strategy

Implementing a Choice Exception Strategy

(0 reviews)

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

Download
Log into Anypoint Platform to download this asset

Overview

Type
Example
Created by
MO
MuleSoft Organization
Published onJun 22, 2017

Versions

VersionRuntime version
1.4.03.8
1.3.33.7
1.2.03.6
1.1.03.5