Error Handling in Mulesoft

amitsingh655 1,215 views 30 slides Aug 15, 2020
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

Error Handling in Mulesoft. Faridabad meetup.


Slide Content

[15th Aug 2020]
[Mule 4 Error Handling]
[Faridabad -India]

All contents © MuleSoft Inc.
Sensitivity: General
Agenda
2
➢Community Introduction
➢Introduction to Error Handling
➢3 Rules to Understand Error Handling
➢Demo
➢Try-Until Successful scopes
➢Error Handling -Priority
➢Q & A session
➢Quiz
➢Networking time

All contents © MuleSoft Inc.
Sensitivity: General
Organizers
3
Welcome everyone! Thanks for joining us!

All contents © MuleSoft Inc.
Sensitivity: General
Surprises!
4
•Participate in an online
Quiz to win the
instructor-led training
classes and certification
exam vouchers. (3
Winners!)
•Be geared up for the
quiz sessions at the end

[ERROR HANDLING IN MULE 4]

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling
6
•An exception occurs when an unexpected
event happens while processing.
•Exception handling is the process of
responding to exceptions when a computer
program runs.
•In Mule we can handle the message exception
at different levels.

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling
7
•At Project level using Default error handler
•At Project level using Custom Global error handler
•At Flow level in exception handling using :
On Error Continue
On Error Propagate
Raise Error
•With in Flow or at processor level using try scope

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling
8
•Whenever there is an error occurred in a Flow, an error Object is created
•It contains many properties . Eg : error.description, error.errorTypeetc.
•Mule identifies based on errorTypeand then route to respective blocks that are
placed in Error Handler.
•errorTypeis combination of Namespace and Identifier :
Eg : HTTP:UNAUTHORIZED
•namespace = HTTP
Identifier = UNAUTHORIZED

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling
9
•Sub-Flow doesn’t have Error Handling scope .
•So its just Flow and a Private flow where you can place On-Error-
Propagate and On-Error-Continue inside “Error Handling” block.
•Either it is Propagate or Continue, Mule Executes all the components
within that block.
Remember : The error will route to error-handlingonly if it identifies
that the errorType of that erroris handled

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling
10
•Mule 4 has one excellent feature of Identifying the types of
errors that can occur within that flow by looking at what
kind of connectors are placed in that particular flow.

All contents © MuleSoft Inc.
Sensitivity: General
3 Rules to Understand Error Handling
11

All contents © MuleSoft Inc.
Sensitivity: General
Rule 1 : Error handling
12
•See if anything is present in Error-Handling .
•Even if there are on-error-propagate and on-error-continue blocks, see that if that
particular errorType is handled.
•If NOT, then Mule will use default Error Handling .
•And if your flow is not called by any other flow , then it will display default value that is
set in Error-Response of HTTP Listener and gives status code as 500 bad default if
nothing is set manually.
•If your flow is called by any other flow, then it will RAISE as an error to the calling flow.

All contents © MuleSoft Inc.
Sensitivity: General
Rule 2 : Error handling
13
•If some Error Handling is present in that particular flow and errorType is
handled (YES condition for RULE1) .
•Check whether it is On-Error-continue or On-Error-Propagate .
•In both the cases, Mule will execute all components within that Error block.
•Next follow Rule 3 which is very important !

All contents © MuleSoft Inc.
Sensitivity: General
Rule 3 : Error handling
14
•IftheerrorishandledusingOn-ErrorPropagate,itwillraiseanerror
back to the calling flow.
•IftheerrorishandledusingOn-ErrorContinue,itwillnotraiseanerror
backtothecallingflowbutcontinuetonextprocessorof“flow-ref”of
callingflow andcontinuesfurtherprocessasitis.
-Butitwillnotcontinuetootherprocessorsintheflowwhereerroris
handled(inOn-ErrorContinueCase).

All contents © MuleSoft Inc.
Sensitivity: General
Rule 3 : Error handling ( Cont… )
15
•Supposeyouhaveonlysingleflow.ThenOn-error-propagateandOn-error-
Continuebehavessameway,insteaderror-continuesgives200statusand
error-propagate gives 500 status.
•Becauseassaid,evenifitserror-continue,itwillnotgotonextprocessor
within the same flow where error is Handled.
•Remember:Thispointisveryimportant.On-error-Continuewillcontinueonly
tonextprocessorofcallingflowbutnotinthesameflow

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -example 1
16
Rule 1
Rule 1 Output :
Default error message with 500
status

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -example 2
17
Rule 1
Output :
”Error Handled in Main flow”
with 200 status
Rule 2
Rule 3

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -example 3
18
Rule 1
Output :
”Error Handled in Main flow”
with 200 status
Rule 2
Rule 3
Rule 1
Rule 2
Rule 3

All contents © MuleSoft Inc.
Sensitivity: General
Error handling -Let’s get our Hands Dirty
19
Hands-on

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -Raise Error
20
•This core component generates a Mule error, as if a failure had occurred, which allows
you to customize its description and type.
•Use this component to only raise:
✓Core runtime errors, such asMULE:SECURITY,MULE:CONNECTIVITY, etc.
✓Custom error types. Eg : ORDER:INVALID
You cannot use a connector’s existing namespace.

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -Try , Until Successful
21
•Try and Until Successful scopes are handled at connector level.
•You can wrap one or more connectors within Try or Until Successful

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -Try , Until Successful
22
•Until Successful retries for all kind of errors. So make Sure when you use it for
HTTP Request component.
•The errorType for Until Successful is MULE:RETRY_EXHAUSTED
•When Error Continue is used within Try block , then it moves to Next processor.
When error propagate is used, it follows Rules of General Error Handling.
•For MUnits , its very important to have Try-Error continue combination for error
scenarios.

All contents © MuleSoft Inc.
Sensitivity: General
Error Handling -Priority
23
•The Error handling has its defined Precedence.
•The error that is handled at connector level takes 1st precedence , followed by
flow level and then global level and finally Default level
•Priorities of Error Handling :
✦1st priority -Connector Level
✦2nd priority -Flow level
✦3rd priority -Project Level
Hands-on

Q & A

QUIZ time

Announce -QUIZ Winners!

All contents © MuleSoft Inc.
Sensitivity: General
Take a stand !
27
•Nominate yourself for the
next meetup speaker and
suggest a topic as well.
•Either for our virtual meetup
speaker, or in-person
meetup speaker.
•Surprise swag for upcoming
Speakers.
•Fill this form -
https://bit.ly/speakar

All contents © MuleSoft Inc.
Sensitivity: General
What’s next
28
•Share:
–Tweet/share in LinkedIn , facebook, Instagram with your pictures with the hashtag
#FaridabadMuleMeetup #MuleSoftMeetup
–Also use #BringMuleSoftConnectToFaridabad to reach our wish to MuleSoft 
–Invite your network to join: https://meetups.mulesoft.com/Faridabad/
•Feedback:
–Contact MuleSoft at [email protected] for ways to improve the program
–Your Feedback is Food for us. https://bit.ly/f-mf
•Our next meetup:
–Date: 29
th
August 2020, 5:00 PM IST
–Location: Virtual
–Topic: Ways to Externalize the Mule Application Logs

THANK YOU 
#Everyone
for becoming a part of such a great
#community.