简体   繁体   中英

How to print exception payload within mule message flow

I have a mule flow within which I am logging the entire payload in String format by following code snippet

<logger level="ERROR" message="#[payload:java.lang.String]"/>

Now if the error occurs there really is no need to print the entire payload. The payload object in the message is null and the exception payload is populated with the relevant exception in it.

If I can print just the exception payload in String format, that would suffice. Does any one know how to log the exception payload from the message ?

    <logger level="ERROR" message=" 
#[groovy:message.getExceptionPayload().getRootException().getMessage()]" /> 

The above code extracts the message related to the cause of exception.

很简单:

<logger level="ERROR" message="#[exception]"/>

表达使用中的小修正:

[groovy:message.getExceptionPayload().getRootException().getMessage()]

If you want to save error into payload you need to transform it:

%dw 2.0
output application/json
---
{
    error: error.detailedDescription,
    errorType: (error.errorType.namespace default '') ++ ":" ++ (error.errorType.identifier default '') ,
    recoverable: false
}

So, into payload you have your error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM