Use the created Dynamic Document Properties to handle the Exception.
Exception Base Class
In case of an uncontrolled exception, the script passes through the Try/Catch Message in DDP_rootCause=DDP_TryCatchMessage. The property name is fix, and that is why you user-defined exception messages should contain a "rootCause" element, so that you can access the error message through that property, no matter if the exception was controlled or uncontrolled.
DDP_userMessage is set to "Something went wrong! Please contact your admin!".
The ParseExceptionMessage Script
The script parses an exception message (expected in [DDP_TryCatchMessage])
and sets well-defined document properties. If [DDP_TryCatchMessage] does not contain a
structured error Json, [DDP_TryCatchMessage] is routed to [DDP_rootCause] property.
If [DDP_TryCatchMessage] is not set the script throws an exception.
The [DDP_TryCatchMessage] must start with "Exception:" (case-sensitive) so that the script runs.
The script parses the following text into dynamic document properties as follows:
Exception: {DDP_ExceptionType}
{DDP_ExceptionJson}
The [DDP_ExceptionJson] is then interpreted as JSON and all elements on the first level
will be turned into dynamic document properties, too. All nested elements are skipped when creating DDPs.
For example:
DDP_TryCatchMessage=
Exception: ApplicationException
{
"statusCode" : 404,
"rootCause" : "Record not found!"
}
DDP_exceptionType='ApplicationException'
DDP_exceptionJson='{
"statusCode": 404,
"rootCause": "Record not found!"
}'
DDP_statusCode ='404'
DDP_userMessage='Something went wrong! Please contact your admin!'
DDP_rootCause = 'Record not found!'