'Log the correct error with meaning full description Mulesoft

I have created a separate file in mule3 for error handling to catch all the errors. I use the reference Exception_Strategy in my interface that points to error-handling choices.

The logs that I use in my error choices are not coming into console logs when the error occurs. It gives a default exception, which seems to point to a system error. I want to show a proper meaning full error when the standard error codes occur like, 400, 401 with meaning full description. Also, if you see the payload in the log is showing as grizzly, how can I modify this with proper description?

Here is my log:

INFO  2022-08-09T18:48:17Z [pool-25-thread-1] org.mule.api.processor.LoggerMessageProcessor: Started flow with pull
INFO  2022-08-09T18:48:59Z [[xxx-servicenow-sys]. xxx-servicenow-sys.02] org.mule.api.processor.LoggerMessageProcessor: uniqueId: 177fbc50-82ac-11ec-aac9-54bc58e14dca local time: 2022-08-09T18:48:59Z
INFO  2022-08-09T18:48:59Z [[xxx-servicenow-sys]. xxx-servicenow-sys -main.stage1.02] org.mule.api.processor.LoggerMessageProcessor: UniqueId: 177fbc50-82ac-11ec-aac9-54bc58e14dca Exit time: 2022-08-09T18:48:17Z Log Exit
ERROR 2022-01-31 16:40:16,996 [[xxx-servicenow-sys]. xxx-servicenow-sys.02] org.mule.exception.DefaultMessagingExceptionStrategy: Exception(s) were found for route(s): 

Route 0:
********************************************************************************
Message               : Response code 401 mapped as failure.
Payload               : org.glassfish.grizzly.utils.BufferInputStream@4f77b640
Element               : / xxx-servicenow-sys -request-call/processors/0/0/0 @ xxx-service-now-sys xxx-servicenow-sys.xml:83 (HTTP Request Changes)
Element XML           : <http:request config-ref="HTTP_Request_Configuration_Changes" path="" method="GET" doc:name="HTTP Request Changes"></http:request>

And this is my error handling.xml

<choice-exception-strategy name="ImplementationChoice_Exception_Strategy">
        <catch-exception-strategy doc:name="400" when="#[message.inboundProperties['http.status'] == '400']">
            <set-variable variableName="error"
                value="#[exception.getDetailedMessage()]" doc:name="Set error flowVar" />
            <set-variable variableName="responseError"
                value="#[org.mule.util.ExceptionUtils.getRootCauseMessage(exception)]"
                doc:name="Set response error message" />
            <set-property propertyName="http.status" value="400"
                doc:name="Set status 400" />
            <logger message="#[&quot;Error: &quot; + flowVars.error + &quot; Response error: &quot; + flowVars.responseError]"
                level="INFO" doc:name="Log Error" />
        </catch-exception-strategy>
        <catch-exception-strategy
            when="#[message.inboundProperties['http.status'] == '401']" doc:name="401">
            <set-variable variableName="error"
                value="#[exception.getDetailedMessage()]" doc:name="Set error flowVar" />
            <set-variable variableName="responseError"
                value="#[org.mule.util.ExceptionUtils.getRootCauseMessage(exception)]"
                doc:name="Set response error message" />
            <set-property propertyName="http.status" value="401"
                doc:name="Set status 401" />
            <logger message="#[&quot;Error: &quot; + flowVars.error + &quot; Response error: &quot; + flowVars.responseError]" level="INFO" doc:name="Log Error"/>
        </catch-exception-strategy>
        <catch-exception-strategy doc:name="404" when="#[message.inboundProperties['http.status'] == '404']">
            <set-variable variableName="error"
                value="#[exception.getDetailedMessage()]" doc:name="Set error flowVar" />
            <set-variable variableName="responseError"
                value="#[org.mule.util.ExceptionUtils.getRootCauseMessage(exception)]"
                doc:name="Set response error message" />
            <set-property propertyName="http.status" value="404"
                doc:name="Set status 404" />
            <logger level="INFO" doc:name="Log Error"
                message="#[&quot;Error: &quot; + flowVars.error + &quot; Response error: &quot; + flowVars.responseError]" />
        </catch-exception-strategy>
            <catch-exception-strategy doc:name="500" >
            <set-variable variableName="error"
                value="#[exception.getDetailedMessage()]" doc:name="Set error flowVar" />
            <set-variable variableName="responseError"
                value="#[org.mule.util.ExceptionUtils.getRootCauseMessage(exception)]"
                doc:name="Set response error message" />
            <set-property propertyName="http.status" value="500"
                doc:name="Set status 500" />
            <logger level="INFO" doc:name="Log Error"
                message="#[&quot;Error: &quot; + flowVars.error + &quot; Response error: &quot; + flowVars.responseError]" />
        </catch-exception-strategy>
    </choice-exception-strategy>

Thanks for helping.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source