How to Ignore Specific Errors in Exception Handling | JSCAPE
Learn how to set an exception handling trigger to ignore a specific type of error. This step-by-step guide includes a video tutorial and examples.
In a previous post, we taught you how to set up triggers that catch and handle trigger errors thrown by other triggers. Now, earlier this week, we received a query from a customer who had this kind of trigger but wanted to ignore a particular trigger event. That is, they didn't want their error handling trigger to execute its succeeding action(s) if the error thrown was a certain type of error. Here's one way to do it.
We'd like to illustrate this in an example but if you want to know the answer straightaway and just skip the example, here it is in a nutshell.
Watch the video
Would you prefer to watch a video version of this tutorial instead? You can play the video below. Otherwise, just skip it if you wish to continue reading.
As you probably know by now, JSCAPE MFT Server triggers have one or more trigger actions. It's actually from these trigger actions that most errors originate. Now, when a trigger action fails, a Trigger Error event is raised. And each of these Trigger Error events are accompanied by a set of properties, each represented by variables.
One of these variables is ActionMessage. This variable holds the error message received when executing the trigger action. Note that this is different from the optional TriggerErrorMessage property. For example, when the SFTP File Download trigger action fails as a result of a missing remote file, which is the file that the action is supposed to download, the action will generate a message that says "Server error: Invalid path" and store this message in the ActionMessage variable.
So, if you want to ignore all errors thrown by the SFTP File Download action caused by missing remote files, you can therefore add a trigger condition in your error handling trigger that ignores this particular Action message.
To do that, just add an expression similar to this:
ActionMessage !# "Server error: Invalid path"
The !# operator means 'Does not contain'
So, this trigger will only execute its accompanying trigger actions if the ActionMessage of the trigger error event DOES NOT CONTAIN the string "Server error: Invalid path". If the ActionMessage contains "Server error: Invalid path", then the error will be ignored and the trigger will NOT execute.
If you want to see an example illustrating how this works, read on.
I have here a trigger named 'sftp pick up'.
This trigger downloads a file from an SFTP server.
As you can see, the file it's supposed to download is named file.txt and it's located in the virtual root path of the account named user1.
Here's that file as seen from the file system. Notice that there's no other file in the file's directory.
If we run the trigger...
... and check the running domain logs, we should be able to trace the 'sftp pick up' trigger's entire trigger execution process, from the moment the trigger was queued down to the moment the trigger was completed. We can even see the part where the file.txt was downloaded.
Let's now head back into the 'sftp pick up' trigger's action parameters and make some changes. Let's change the name file.txt to file1.txt and leave everything as is. Because there's no file1.txt in this remote path, this trigger should fail.
So, if we run this trigger again ...
... and check the logs, we should see the same trigger execution process. But this time, it already includes a couple of entries indicating an error. As you can see, the SftpFileDownloadAction failed and it generated a message that said something like: "Server error: Invalid path..."
We'll use that message in a short while.
But first, let's go back to the Triggers module. You might not have noticed it earlier, but I have another trigger named 'error detector'.
This trigger is an error handling trigger, so it listens to the Trigger Error event type. This was previously disabled, so let's enable it now.
If we look at the trigger conditions dialog, we see that this trigger only responds to errors thrown by the 'sftp pick up' trigger whose ActionMessage contains the string "Server error: invalid path".
Since this is only an example, I just set this trigger to generate the following message on system out.
Let's now see this trigger in action. Let's run the 'sftp pick up' trigger again.
So, if we review the logs, we see that:
- The 'sftp pick up' trigger was able to run;
- Its 'SFTP file download' action failed; and then, after that,
- The 'error detector' trigger kicked in
And if we scroll down further, we'll see that, because the conditions of the 'error detector' trigger were satisfied, its subsequent trigger action, a SystemOut action, printed the message specified earlier.
In a production environment, the action might be different. It might be an Append File action that prints details of the error in a separate error log file or perhaps a Send Email action that sends out email alerts to a server administrator.
Alright, that's well and good but this is not the kind of example we came here for. What we wanted was a trigger that would ignore a certain type of error. So, let's proceed and do that. Let's modify this trigger so that it will instead ignore errors coming from the 'sftp pick up' trigger that contain the string "Server error: Invalid path" in its ActionMessage. If this string is found, then the trigger will not execute.
There are a number of possible errors that can be thrown by the 'sftp pick up' trigger's SFTP File Download action, but what I can think of right now is when one of the connection settings is wrong; in which case, the trigger action will be unable to connect and the connection attempt will timeout.
So, let's edit the 'sftp pick up' trigger and change some connection settings in its SFTP File Download action. Let's just change port number to 23. Since the remote SFTP service is listening on port 22, this trigger action will be unable to connect and eventually timeout.
If you're testing this out yourself, you might want to reduce this trigger action's timeout value to, say, 5 seconds. That way, you won't have to wait too long for the connection attempt to timeout.
After saving those changes, we'll now want to modify our 'error detector' trigger.
We'll want it to ignore only those errors that contain the string "Server error: Invalid path" in its ActionMessage. To do that, we just change the # (contains) operator to the !# (not contains) operator.
So, now, the trigger condition that you see on the screen now says:
This trigger should only respond to trigger errors coming from the trigger 'sftp pick up' if their ActionMessage does not contain the string "Server error: Invalid path".
To avoid any confusion in the ActionMessage entries in the logs, let's just remove the part that says "file1.txt not found!!!!". So, all that's going to be printed out in the logs is:
Action message: [the value of the ActionMessage variable]
So, once again, let's fire up the 'sftp pick up' trigger.
You might want to wait at least 5 seconds before checking the logs to give the trigger action's connection attempt to time out.
Once those 5 seconds elapse, you can then check the running log. You'll see that both the 'sftp pick up' and the 'error detector' triggers have fired. And then, once you check the log entries for the 'error detector' trigger, you should see the SystemOutAction's action message saying: "Action message: Connection refused".
So what exactly happened here? Because the ActionMessage wasn't "Server error: Invalid path", the 'error detector' trigger simply proceeded to execute its SystemOut trigger action.
So, what would happen if the ActionMessage is "Server error: Invalid path"? Let's find out.
Let's go back one more time to the 'sftp pick up' trigger...
... and let's change these settings again. Let's bring back the port number to 22 and the remote file to file1.txt. This means, this trigger will be able to connect but it will still fail because it won't be able to find the remote file it's supposed to download. Remember that the correct file name is file.txt and we're attempting to download a file1.txt.
So, if we run this trigger one last time...
... and then check the logs, we should see that, while the 'sftp pick up' trigger runs and fails, the 'error detector' trigger does not run at all.
That's it. Now you know how to configure an error handling trigger to ignore specific errors.
Would you like to try this out yourself? Download the FREE, fully-functional Starter Edition of JSCAPE MFT Server now.Download JSCAPE MFT Monitor