Compare response to message property and take different actions on result (enable ErrorHandling chain if error occurs)

This script compares response data (in this case something from a message header) to data that has been previously entered into a message property.

 
// Get prior message.
var msg = $context.currentItem.previousItem;

// Get 'Server' response header from prior response.
// This examples assumes a "Server: Apache" response header  
// from hitting this url: https://turbotax.intuit.com/
var responseData = msg.getResponse(msg.RESPONSE_HTTP_HEADER, "Server");

// Put 'Server' response header in script log/events list.
$context.result.postMessage($context.result.LEVEL_INFO, "responseData: " + responseData);

// Put contents of message property (myProp) from prior message 
// into a javascript variable and output to script log/events list.
// Message property is named 'myProp' with contents of 'Apache';
// failure case has property contents of 'Not Apache'.
var preStoredMessageProperty = msg.propertyList.getPropertyValue("myProp");
$context.result.postMessage($context.result.LEVEL_INFO, "preStoredMessageProperty: " + preStoredMessageProperty);

// Compare response to message property and take appropriate path.
if (responseData == preStoredMessageProperty)
{
  $context.result.postMessage($context.result.LEVEL_INFO, "Response DOES match");
}
else
{
  $context.result.postMessage($context.result.LEVEL_ERROR, "Response DOES NOT match");
  
  // Set all subsequent messages to NOT play
  var nextItem = $context.currentItem.nextItem;
  while (nextItem != null)
  {
    nextItem.setRepeat(nextItem.REPEAT_TIMING_SERIAL, nextItem.REPEAT_TYPE_COUNT_CONSTANT, 0, nextItem.REPEAT_DISTRIBUTION_CONSTANT, 0);
    nextItem = nextItem.nextItem;
  }
  
  // Enable "ErrorHandling" chain.
  // Note: ErrorHandling chain was disabled in the clip by default
  // (i.e. serial repeat = 0)
  chain =  $context.currentClip.getChild("ErrorHandling");
  chain.setRepeat(
  chain.REPEAT_TIMING_SERIAL, 
  chain.REPEAT_TYPE_COUNT_CONSTANT, 
  1, // this means do it ONE time
  chain.REPEAT_DISTRIBUTION_CONSTANT, 
  0);
}

// Clear message response from memory since it is no longer needed.
msg.clearResponse();