Академический Документы
Профессиональный Документы
Культура Документы
Sample Response
{
“errorCode”: “STS-400-INVALID_REQUEST”,
“errorMsg”: “Input Request is not valid. Please verify and try again.”
HTTP Code Error Code in Resp. Error Msg in Resp. Used When Comment
400 STS-400- Use default APIKit Input validation
INVALID_REQUEST message Error by APIkit
400 STS-400- Request have When parsing
INVALID_FORMAT invalid format the input fails
<exception>
400 STS-400- Request is invalid In Case any
BAD_REQUEST <exception> other expected
error comes
while
processing the
request. ex.
missing
information
404 STS-400-NOT_FOUND Record <id> not Unable to find
found. the requested
resource in the
system
500 STS-500- Unable to connect When unable to
CONNECTION_ERROR with <system> connect to the
endsystem
500 STS-500- Unexpected When there is
INTERNAL_ERROR exception is some
<exception> unexpected
failure during
the process.
Implementation in Mule 4
Creating Global exception strategy
Create the below mentioned error handler.
Mark the exception strategy created above as global by creating a configuration as show in the
image below.
Adding exception for the main flow.
As mentioned above for mule 3 code, the same logic is added in mule 4 with the help of request-
reply scopes. Taking the similar dataweave transformation code as sample. Find below the
screenshot of the same in mule 4.
Please not the use of try scope and error handlers “On Error Propagate” and “On Error Continue”.
The dataweave in error handling part is configured as shown below.
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-
ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-
http.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config"
doc:id="f627ea5c-95a4-4349-ae3f-8028ddc8088d" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<configuration doc:name="Configuration" doc:id="aa3a59a0-00fc-4259-adca-4050ac74109e"
defaultErrorHandler-ref="sample-exception-handlingError_Handler" />
<flow name="sample-exception-handlingFlow" doc:id="a26e53ca-6b79-4c01-a04d-79b94018721d" >
<http:listener doc:name="Listener" doc:id="177149ab-742f-41d3-abcd-2aeec26f4804" config-
ref="HTTP_Listener_config" path="/api">
<http:response statusCode="#[vars.httpStatus default 500]" />
</http:listener>
<try doc:name="Try" doc:id="042d5041-66f4-4706-ad72-a0340f571f53" >
<ee:transform doc:name="Sample Transformation" doc:id="4ca9bb40-ca2f-4681-a3a9-
4f13dc131dde" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
"Sample Transformation"]]></ee:set-payload>
Snippet 2/2
Description
The system API will be response for passing the appropriate error message with the complete
information of error to the consumer API. Which can be either a process API or an Experience API.
If All three types of APIs are involved. Experience, Process and System the email logic should be
placed in process API.
So Process/Experience API can have two kind of failure scenarios either an exception while call the
system API. Or a partial success. If there is exception in the process as shown above, It will be
handled to read the error, log it and then create the appropriate email API request and call the email
API to send the email.
In case of partial success, Read the response of system API. And create the request for email API
using the failed records and send the required information to the email API to trigger the email.