'Fetching error message in Mule 4 not working
I run the code in debug mode and realized that external service is returning me error message below error message is coming in the path error.exception.cause.errorMessage.typedValue.value Its value is as below.
typedValue.value = {"status"":"Bad Request", "message":"Invalid data"}
I want to get the message "Invalid data" in var.
My code is as follows
output application/java
var adminEmail = vars.adminEmail
var salesRepEmail = if (!isEmpty(vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress))
[vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress]
else
p('emailNotifications.nonStarterNotification.defaultEmail') splitBy(",")
var declineReason = error.exception.cause.errorMessage.typedValue.value
I have tried
var declineReason = if(error == null) vars.errorDescription else (error.exception.cause.errorMessage.typedValue.value default "Bad request") as String
Also tried
var declineReason = if(error == null) vars.errorDescription else flatten(error.exception.cause.errorMessage.typedValue.value.message)
error.exception.cause.errorMessage.typedValue.value returns null.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
