Sidebar

Using message.discard() and the message is going to the error queue. How do I fix this?

0 votes
453 views
asked Oct 10, 2017 by brandon-w-8204 (33,270 points)
edited Oct 11, 2017 by brandon-w-8204
I am getting a "JavaException: javax.script.ScriptException: com.qvera.qie.web.exception.MessageDiscardException: message.discard() called."  error and the message is going to the error queue.

1 Answer

0 votes

When processing a message using QIE, the script runs in the Rhino Script Engine.  The only way to stop the process is for QIE to throw an exception.  With this in mind, when message.discard() is called, QIE throws a special exception called 'MessageDiscardException'.  When QIE catches the exception it checks to see if it is this special 'MessageDiscardException' and if it is, the message is moved to the completed queue instead of being moved to the error queue.

In the event that your script calls message.discard() inside of a try/catch statement, the catch will consume this special exception.  Now instead of allowing QIE to process the exception you have to deal with it inside of your script.  A general rule of thumb would be that you shouldn't call message.discard() inside of a try/catch statement.  Always call it outside of the try/catch.

If you must call it from inside of a try/catch, then you will need to evaluate the message error that you caught to determine if the exception is this special one or not.  If you determine that it is this special exception, then you would simply call the message.discard() again to allow QIE to catch and process this exception.

Here is an example of catching the exception and evaluating if it is the special 'MessageDiscardException' or not, if it is, the message.discard() is thrown again, otherwise the error message is thrown and the message is sent to the error queue.

try {
   //something in the try
   message.discard();
} catch (e) {
   // See if the error message contains 'MessageDiscardException'
   if (StringUtils.containsIgnoreCase(e, 'MessageDiscardException')) {
      // this is the special exception, so we call message.discard() again to go to the completed queue
      message.discard();
   } else {
      // Since this is not the special exception, we throw the exception again and the message goes to the error queue
      throw e;
   }
}

answered Oct 10, 2017 by brandon-w-8204 (33,270 points)
...