bnoguchi/everyauth — pull request #173 by symposion (2012-02-06 13:06:57+00:00)
Title: Suggested fix for https://github.com/bnoguchi/everyauth/issues/36

I've slightly modified the way step sequences are run so that a connect/express "next" function is available in the appropriate places. When an error occurs, this is called with it rather than the step sequence just halting or continuing inappropriately. Some assumptions/notes:

1. There's never a need for next() to be called without an error - where a routeTriggeredSequence is in play it will be the last item of middleware for non-error cases.

2. I have left the existing error handler mechanism in place for the moment to avoid breaking things. If existing error handlers throw exceptions my code will not work correctly. I would rather see the error handlers removed, but if they are kept they could be wrapped in try-catch to fix this. The new error handling could even be an option for maximum backwards compatibility. Happy to update the pull request whichever way you think this is right.

3. I have made it work correctly (I think) for breakTo sequences, but I note that there's also a breakTo method on Promise. This didn't seem to be used anywhere, and looked redundant, so I removed it. It could be made to work with what I've done but it would involve tying Promise even more closely to the steps/modules which seemed a poor design choice. Would be interested to know if I've missed some crucial use-case here.

4. I have assumed that next will always be the last parameter passed to stepSequence.start, but I have a check to ensure that there are actually more params available than the first step "accepts". If there aren't, next() is replaced with a no-op.

Many thanks for a great library; I hope this code is helpful and can find it's way back into the main project.