Global Exception Handling Custom Error Connector In MuleSoft
shyamraj55
422 views
40 slides
Oct 16, 2024
Slide 1 of 40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
About This Presentation
Global Exception Handling Custom Error Connector In MuleSoft | Bangalore MuleSoft Meetup #43
This presentation covers a technical discussion on error handling and custom model development using MuleSoft, a platform for building application networks. It outlines key topics such as error-handling str...
Global Exception Handling Custom Error Connector In MuleSoft | Bangalore MuleSoft Meetup #43
This presentation covers a technical discussion on error handling and custom model development using MuleSoft, a platform for building application networks. It outlines key topics such as error-handling strategies, building custom models, and implementing global exception handling. The slides include a demo on creating custom XML SDKs and emphasize the importance of robust exception management for large-scale applications. Additionally, it explores the process of developing and publishing custom connectors to the MuleSoft Exchange, focusing on version control and addressing production error challenges.
2 Bangalore Meetup will start shortly...meanwhile @ Attendees : Kindly introduce yourself in Chat Name Company Location Mule Experience
3 Introduction Error handling Custom Connector Global Exception Use Case Q&A Meetup: Feedback & Upcoming Events Agenda
4 Meet your Bangalore Meetup Leader
5 Meet your Baltimore Meetup Leader
6 Both the speaker and host are organizing this meet up in individual capacity only. We are not representing our companies here. This presentation is strictly for learning purpose only. Organizer/Presenter do not hold any responsibility that same solution will work for your business requirements also. This presentation is not meant for any promotional activities. This meeting will be recorded and shared. Safe Harbour Statement
Support a variety of sources Correlating and cross referencing Searching,filtering and highlighting Visualize Alerting Retention
Error Module
System Errors Mule throws a system error when an exception occurs at the system level and no Mule event is involved. A system error handler manages exceptions that occur: During application startup. When a connection to an external system fails. When a system error occurs, Mule sends an error notification to registered listeners, logs the error, and if the error is caused by a connection failure, executes a reconnection strategy. System error handlers are not configurable in Mule.
Messaging Errors Mule throws a messaging error (a Mule error ) whenever a problem occurs within a flow of a Mule app, where Mule events and the messages they contain are processed. You can handle Mule messaging errors in more than one way: You can rely on the default error handling mechanism. Within a flow, you can set up On-Error components (On Error Continue and On Error Propagate) inside the flow’s built-in Error Handler component. These components can contain any number of components to process the error. Outside a flow, you can set up an Error Handler component and reference it from other Error Handler configurations. The global Error Handler can also contain On-Error components and their contents. It is also possible to set up error handling from within a Try scope that resides in a flow. The scope contains a built-in Error Handler in which you can configure On-Error components and their contents.
Event Processor
On Error Propagate
On Error Propagate
On Error Continue
On Error Continue
global error-handling Click Global Elements to open Global Configuration Elements. Global Elements is located below the Studio canvas. In Global Configuration Elements, click Create to open the Choose Global Type dialog. c.From the dialog, select Global Configuration -→ Configuration, and then click OK to open the Configuration dialog. d.From the select Configuration dialog, select allErrorHandler for the Default Error Handler field, and click OK.
Default error handler
Connector Api Details Common Errors Custom Errors ResponseKey PreviousErrors
Features Converts all errors into proper API JSON request body and HTTP status code. Customize error messages for HTTP & APIKIT errors. Customize error message for the default error when no errors matched: 500 - Internal Server Error. Provide custom error mappings with dataweave. Automatically propagate errors from downstream APIs automatically, if desired. Automatically use the generated error description for the error response message, if desired. Compatible with on-error-propagate and on-error-continue error handlers. All error types are parsed by this module.
Common Errors Tab
Common Errors Tab Customize APIKit & HTTP Error Messages Modify the error message for the APIKit and HTTP errors on the Common Errors tab. This field supports dataweave for dynamically generated messages if needed. The response status code and error reason (phrase) cannot be changed for common errors on this tab. Additional errors not covered here can be mapped to the same status codes with the Custom Errors feature. If you want to change the status code or reason, use the Custom Errors feature to override the desired APIKit or HTTP exceptions.
Custom Errors Tab Customize Full Error Definitions You can add any number of custom error definitions for the module to include in the mapping. This is done by defining these custom error mappings inline or in a dataweave file . The screenshot shows using a file.
Use Generated Error Message You can set the error message to the generated error description from the error object, error.description, based on the Use Generated Error Description Instead selection. If it evaluates to true, the generated error will be used as the error message. If it evaluates to false, the user-provided message will be used.
Previous Errors Connectors usually generate error responses their own error responses and wrap the actual error response from the external system in the error object. This causes the external system's response to be lost and not propagated back to the API's caller. The previous error feature allows the module to retrieve the external system's error response from the error object and use that as the error message.
Custom XML SDK Custom Xml SDK is an Mulesoft Provided Kit to develop our own customizable connector to fullfill our requirements. Custom XML SDK is much more easier compare to Java SDK We use Custom XML SDK to make our ChatGpt Connector and Interact with OpenAI system with different operational endpoints in Single Module
Steps to Develop XML SDK Add the Mulesoft Repository in .M2 repository settings.xml <profiles> <profile> <id>Mule</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>mulesoft-releases</id> <name>MuleSoftRepository</name> <url>http://repository.mulesoft.org/releases/</url> <layout>default</layout> </repository> </repositories> </profile> </profiles>
Execute Maven Command Use Maven (mvn) from to execute the following command:(You can use your own connect names) mvn archetype:generate -DarchetypeGroupId=org.mule.extensions -DarchetypeArtifactId=mule-extensions-xml-archetype -DarchetypeVersion=1.2.0 -DgroupId=org.mule.extension -DartifactId=Sanket-demo-connector-mule-extension -DmuleConnectorName=Sanket-demo-connector Once Bulid is Success we can able to see XML SDK template in our Project root
Features in XML SDK Module The <module> element is the root of an XML SDK module. It contains all properties and operations that belong to the module. Operations: An <operation> element defines a set of input parameters and a single output(Like a function) Input parameters: a set of parameters that declares the type to be entered when calling the operation. Body: where the action is performed. It executes the sequence of components, like flows. Output: declares an output type for your XML SDK module.
Sdk Attributes defaultValue Name of the parameter Use Required or Optional Type DataType Password Hiding the value from UI displayName Adds the Display for the Field in UI hyphenated version of the name Order Order the Fields name in UI Tab Sets group of Fields in one category Doc:description Gives the Description of Parameter in UI
Publishing XML SDK to Exchange Add the below Management in Pom and make server Id credentials in .M2 settings.xml in my case EXCAHGE2 is my server id and add organization ID In Distribution Management <distributionManagement> <snapshotRepository> <id>Exchange2</id> <name>Exchange Repository</name> <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/ORGID/maven</url> <layout>default</layout> </snapshotRepository> <repository> <id>Exchange2</id> <name>Exchange Repository</name> <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/ORGID/maven</url> <layout>default</layout> </repository> </distributionManagement> Run Mvn Deploy once it is Success able to see connector in Exchange
Use Cases for Demo
Demo Time !
Q&A
37 Share : Tweet using the hashtag #MuleSoftMeetups #MuleMeetup Invite your network to join: https://meetups.mulesoft.com/san-francisco/ Feedback : Fill out the survey feedback and suggest topics for upcoming events Contact MuleSoft at [email protected] for ways to improve the program Nominate Yourself as Meetup Speaker: Amazing opportunity to public speaking, broadening skills and expanding network Knowledge Shared is Knowledge Squared!