Sidebar

How do I use the Channel Error Handler Script?

0 votes
503 views
asked Apr 24, 2019 by rich-c-2789 (17,430 points)
edited Apr 24, 2019 by rich-c-2789

I currently have error handling in each of my mapping nodes. I noticed the new Error Handler tab on the source node. How would using this differ from the error handling in the mapping nodes?

1 Answer

0 votes

The Channel Error Handler Script is a new feature available as of version 3.0.47. It does not replace error handling in mapping nodes. Although, you may find that some of your error handling could be moved here, it was added to provide additional flexibilty in handling errors. You will need to review the error handlers in your mapping nodes and decide on a case by case basis if it make sense to use this new feature in addition to vs instead of etc.

What does it do then?

The Channel Error Handler Script can be used to catch any errors thrown in a mapping or condition node while a message is being processed. Note: It does not catch errors in source or destination nodes.

To use it first enable it. Then implement your error handling logic. A default script is provided with a todo to remind you that you need to implement something.

Once enabled the Channel Error Handler Script will be triggered by the following:

  • o An unexpected error occurs that is not handled.
  • o A 'throw' statement is used but not handled.
  • o message.error() is called.
  • o qie.simulateSendError() is called. Note: this should only be used in ack scripts Not in mapping or condition nodes.
  • 0 qie.throwAckError() is called. Note: this should only be used in ack scripts. Not in mapping or condition nodes.

 

How messages flow when an error occurs:

Disabled: No change. Messages flow from the mapping that caused the error to the error queue.

Enabled: Messages flow from the mapping that caused the error to the Channel Error Handler Script. If the Channel Error Handler Script includes a call to message.discard() the message will flow to the completed queue else to the error queue (default).

 

When should I use the Channel Error Handler Script vs. a try/catch in a mapping node:

 

Use the Channel Error Handler Script to:

  • o Skip processing other mapping functions or nodes yet handle an error before going to the error queue.
  • o Post a message response in a central location before going to the error queue.
  • o To discard the message instead of sending it to the error queue.
  • ...

 

Use try/catch error handlers in mapping nodes to:

  • o Close a resource used in the mapping node or function
  • o Continue to the next mapping function or mapping node.
  • o Try again.
  • o Try an alternate method.
  • ...

 

The Channel Error Handler Script is also called while testing a message.  This will be indicated like shown in the screen shot below.

Example that returns a simple response when an error occurs then forwards the message to the error queue:

function errorHandler(source, message, messagePath, exceptionToHandle, exceptionMessage, exceptionClass, exceptionFunction, exceptionLine) {
   if (qie.awaitingMessageResponse()) {      
      qie.postMessageResponse('<ERRORRESPONSE>' + exceptionMessage + '</ERRORRESPONSE>');
   }
}

This example first checks to see if a response was already posted before the Channel Error Handler Script was called.  If not, it posts a response.  Note: you will need to replace the content of the response in this example with something specific to your use case.

answered Apr 24, 2019 by rich-c-2789 (17,430 points)
edited Jan 30, 2020 by rich-c-2789
...