I am trying to get the original exception message that caused the TemporalFailure in my workflow.
I thought I could use getOriginalMessage()
on the TemporalFailure
itself which would figure out the nested message to return, but it doesn’t appear that way. It just returns what caused the failure.
Instead, I have to do something like this to get the error message:
private void sendOrderErrorEmail(UUID requestId, PurchaseLicenseRequest request, TemporalFailure e) {
String error = e.getOriginalMessage();
if (e instanceof ActivityFailure af) {
Throwable cause = af.getCause();
switch (cause) {
case ApplicationFailure afe -> error = afe.getOriginalMessage();
case CanceledFailure cfe -> error = cfe.getOriginalMessage();
default -> error = e.getOriginalMessage();
}
}
}
I guess I thought that the hierarchy chain would be traversed to get the root message.
Something like this when using ExceptionUtils.getRootCauseMessage(e)
from Apache Commons
I guess we have to know in advanced the potential chain of exceptions that could happen if we need to parse out the ultimate error message or use something like ExceptionUtils
to do the work.
Just asking if that is the correct way to process error messages.