Set up StopIteration exceptions properly in node.js backend