At the moment our emails are using a try and catch SSJS wrapping and stringify to log the error into a DE. We need to be able to catch any error happening due to the use of different blocks. At the moment we use SSJS try and catch, the following error has been logged into the debug DE however it has also been emailed to the customer .
Call to update the salesforceobject Account ID = 0017Y00001XXXXXXX failed! Error status code: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY\nError message: AccountTrigger: execution of AfterUpdate\n\ncaused by: System.DmlException: Update failed. First exception on row 0 with id 0PK7YXXXXX015YtXXXX; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []\n\nClass.IndividualService.syncIndividualFields: line 77, column 1\nClass.AccountTriggerHandler.handleAfterUpdate: line 139, column 1\nTrigger.AccountTrigger: line 37, column 1"
We don't want the customer to receive the email with the error message. And we need to block the send when this happens.
Support suggested to use Raise Error to block the send completely as SSJS will log but still send. I only find example with IF statement, but I don't have a way to see if the record is locked. So I thought to use the SSJS to catch the error and then raise the error with ampscript.
I tried to add the raise error in the SSJS catch part. The email is not sent but also the error is not logged into the data extension. I am not sure if the following syntax incorrect? Should the raise error be outside of the SSJS?
As I cannot reproduce the record lock issue I tried by adding the wrong contact key however seems like the try and catch is not catching this error and not logging. So I don't understand if it's a limitation or a syntax issue
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
**<script runat="server">
Platform.Load("Core","1");
try{
</script>**
<div style="font-size:0; line-height:0;">
***..... email blocks and content......***
<script runat="server">
}
catch(e) {
Write(Stringify(e.message))
Platform.Function.InsertDE("EmailDebugLog" ,["Template","ErrorMessage"],["1",Stringify(e.message)]);
RaiseError("Error occurred",true)
}
</script>
</body>
</html>