I am working on building a Mulesoft application that GETs a bunch of information from one API endpoint, transforms it and makes a POST to another endpoint. However, when I try to make a POST that has some validation error (according to criteria set by the destination API), the POST fails with a 400 ERROR. In Postman, I can see the validation errors that prevented a successful POST request, I fix those and POST again then I get a successful POST result. Indicated by a JSON response with an {ID:VALUE}
returned to me from the API.
I want to write a flow where I can validate first, grabbing/logging the validation errors, and POST all successful requests. I have an error handler that logs a failure and continues with the rest of the POST request in a for each scope.
How can I log the validation error message that is returned to me from the external API in Mulesoft Logger? I tried to look inside each part of the "error" object but no luck.
Sample POST Request in Postman (validate only): POST /v1/employees?clientNamespace=myNameSpace&isValidateOnly=true
Sample POST Response via Postman (Failed POST):
"requestId": "01c1c37b-ca31-4cba-b954-6ea0c4139d33",
"processResults": [
{
"code": "HR_Employee_EmployeeDataSaveFailure",
"context": "Employee",
"level": "ERROR",
"message": "Failed to Save Employee Data"
},
{
"code": "HR_Employee_BirthCountryAndMaidenNameRequired",
"level": "WARN",
"message": "Birth Country and Birth Name - Values are required if the Social Insurance Number is missing for automatically registering the employee to the Social Insurance companies."
},
{
"code": "HR_Employee_BirthCountryMissing",
"level": "WARN",
"message": "Birth Country: Value is missing"
},
{
"code": "HR_Employee_BirthCityMissing",
"level": "WARN",
"message": "Birth City: Value is missing"
},
{
"code": "HR_Address_InvalidZipOrPostalCodeForCountry",
"context": "Employee.Addresses[0].PostalCode",
"level": "ERROR",
"message": "The zip or postal code 252500-99 is not valid for the country: DEU"
}
}
Sample POST Request in Postman: POST /v1/employees?clientNamespace=myNameSpace&isValidateOnly=true
Sample POST Response (successful, with warnings):
"Data": {
"XRefCode": "100022"
},
"ProcessResults": [
{
"Code": "HR_EmployeeWorkAssignmentManager_HasBeenEndDated",
"Context": "ManagerName",
"Level": "WARN",
"Message": "Direct Manager - Value will be assigned an end date of 4/28/2025 due to the effective dates of the employee’s work assignments."
}
]
}
By looking at this response, I know what to do or who to notify about the invalid values/input/warnings. However, without this, I just have a generic 400 Bad Request
Error.
Currently, I can only get the response headers from the error
entity.
[
com.mulesoft.mule.runtime.core.internal.processor.TransformMessageProcessor@225b0b38,
post-employee-detailsFlow/processors/2/processors/0/processors/1,
.mule.runtime.core.internal.processor.LoggerMessageProcessor@3e2de4a7,
.mule.runtime.core.internal.processor.LoggerMessageProcessor@96bc62c
].switchOnErrorScheduler @5ccd130d] [processor: post-employee-detailsFlow/processors/2/processors/0/errorHandler/0/processors/0; event: 23acac40-0cb8-11f0-a7e1-5ce91eb7799f] .mule.runtime.core.internal.processor.LoggerMessageProcessor: Error Body:
.mule.runtime.core.internal.message.ErrorBuilder$DeserializableErrorImplementation
{
description=HTTP POST on resource ':80/api/myClientNamespace/v1/employees' failed: bad request (400).
detailedDescription=HTTP POST on resource ':80/api/myClientNamespace/v1/employees' failed: bad request (400).
errorType=HTTP:BAD_REQUEST
cause=.mule.extension.http.api.request.validator.ResponseValidatorTypedException
errorMessage=
.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation
{
payload=.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@27a33622
mediaType=application/json; charset=UTF-8
attributes=.mule.extension.http.api.HttpResponseAttributes
{
Status Code=400
Reason Phrase=Bad Request
Headers=[
date=Sat, 29 Mar 2025 16:17:39 GMT
content-type=application/json
content-length=620
connection=keep-alive
access-control-allow-credentials=true
strict-transport-security=max-age=31536000; includeSubDomains
cf-cache-status=DYNAMIC
server=cloudflare
cf-ray=9280adbb5a7ea21f-MSP
]
}
attributesMediaType=*/*
}
suppressedErrors=[]
childErrors=[]
}
If there is no error at all, I can do a successful POST. I want to eventually deploy this to CloudHub and need at least some essential logging, but currently just developing locally.
I am working on building a Mulesoft application that GETs a bunch of information from one API endpoint, transforms it and makes a POST to another endpoint. However, when I try to make a POST that has some validation error (according to criteria set by the destination API), the POST fails with a 400 ERROR. In Postman, I can see the validation errors that prevented a successful POST request, I fix those and POST again then I get a successful POST result. Indicated by a JSON response with an {ID:VALUE}
returned to me from the API.
I want to write a flow where I can validate first, grabbing/logging the validation errors, and POST all successful requests. I have an error handler that logs a failure and continues with the rest of the POST request in a for each scope.
How can I log the validation error message that is returned to me from the external API in Mulesoft Logger? I tried to look inside each part of the "error" object but no luck.
Sample POST Request in Postman (validate only): POST /v1/employees?clientNamespace=myNameSpace&isValidateOnly=true
Sample POST Response via Postman (Failed POST):
"requestId": "01c1c37b-ca31-4cba-b954-6ea0c4139d33",
"processResults": [
{
"code": "HR_Employee_EmployeeDataSaveFailure",
"context": "Employee",
"level": "ERROR",
"message": "Failed to Save Employee Data"
},
{
"code": "HR_Employee_BirthCountryAndMaidenNameRequired",
"level": "WARN",
"message": "Birth Country and Birth Name - Values are required if the Social Insurance Number is missing for automatically registering the employee to the Social Insurance companies."
},
{
"code": "HR_Employee_BirthCountryMissing",
"level": "WARN",
"message": "Birth Country: Value is missing"
},
{
"code": "HR_Employee_BirthCityMissing",
"level": "WARN",
"message": "Birth City: Value is missing"
},
{
"code": "HR_Address_InvalidZipOrPostalCodeForCountry",
"context": "Employee.Addresses[0].PostalCode",
"level": "ERROR",
"message": "The zip or postal code 252500-99 is not valid for the country: DEU"
}
}
Sample POST Request in Postman: POST /v1/employees?clientNamespace=myNameSpace&isValidateOnly=true
Sample POST Response (successful, with warnings):
"Data": {
"XRefCode": "100022"
},
"ProcessResults": [
{
"Code": "HR_EmployeeWorkAssignmentManager_HasBeenEndDated",
"Context": "ManagerName",
"Level": "WARN",
"Message": "Direct Manager - Value will be assigned an end date of 4/28/2025 due to the effective dates of the employee’s work assignments."
}
]
}
By looking at this response, I know what to do or who to notify about the invalid values/input/warnings. However, without this, I just have a generic 400 Bad Request
Error.
Currently, I can only get the response headers from the error
entity.
[
com.mulesoft.mule.runtime.core.internal.processor.TransformMessageProcessor@225b0b38,
post-employee-detailsFlow/processors/2/processors/0/processors/1,
.mule.runtime.core.internal.processor.LoggerMessageProcessor@3e2de4a7,
.mule.runtime.core.internal.processor.LoggerMessageProcessor@96bc62c
].switchOnErrorScheduler @5ccd130d] [processor: post-employee-detailsFlow/processors/2/processors/0/errorHandler/0/processors/0; event: 23acac40-0cb8-11f0-a7e1-5ce91eb7799f] .mule.runtime.core.internal.processor.LoggerMessageProcessor: Error Body:
.mule.runtime.core.internal.message.ErrorBuilder$DeserializableErrorImplementation
{
description=HTTP POST on resource 'http://staginghostname:80/api/myClientNamespace/v1/employees' failed: bad request (400).
detailedDescription=HTTP POST on resource 'http://staginghostname:80/api/myClientNamespace/v1/employees' failed: bad request (400).
errorType=HTTP:BAD_REQUEST
cause=.mule.extension.http.api.request.validator.ResponseValidatorTypedException
errorMessage=
.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation
{
payload=.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@27a33622
mediaType=application/json; charset=UTF-8
attributes=.mule.extension.http.api.HttpResponseAttributes
{
Status Code=400
Reason Phrase=Bad Request
Headers=[
date=Sat, 29 Mar 2025 16:17:39 GMT
content-type=application/json
content-length=620
connection=keep-alive
access-control-allow-credentials=true
strict-transport-security=max-age=31536000; includeSubDomains
cf-cache-status=DYNAMIC
server=cloudflare
cf-ray=9280adbb5a7ea21f-MSP
]
}
attributesMediaType=*/*
}
suppressedErrors=[]
childErrors=[]
}
If there is no error at all, I can do a successful POST. I want to eventually deploy this to CloudHub and need at least some essential logging, but currently just developing locally.
Share Improve this question edited Mar 29 at 17:13 elegantcomplexity asked Mar 29 at 16:39 elegantcomplexityelegantcomplexity 158 bronze badges1 Answer
Reset to default 1You can use error.errorMessage
to get it. When a connector like "HTTP Request" returns a response that is interpreted as an error, usually this field is populated with the original message. You can read about them in the official doc: https://docs.mulesoft/mule-runtime/latest/mule-error-concept#selector_expressions
The
errorMessage
element becomes available when a connector or component exposes the message that it has interpreted as an error. For example, when an HTTP request receives a status code that Mule treats as an error, the process fails and also populates theerrorMessage
with information about the error. You can then gain access to error message attributes (metadata) and to the payload itself with#[error.errorMessage.payload]
for the payload and#[error.errorMessage.attributes]
for the metadata. In the case of an HTTP request that returns an error, you can then use#[error.errorMessage.attributes.statusCode]