caolan/cookie-sessions — pull request #21 by hiddentao (2012-01-13 01:03:56+00:00)
Title: CoffeeScript rewrite + Added an onError setting to the initial call

I started off by merging publickeating's excellent work (https://github.com/caolan/cookie-sessions/pull/14) and then went onto rewrite the code in CoffeeScript - the code easier to read and it makes it easier to ensure generated code is JSLint compliant. A Cakefile is included to generate the `lib/cookie-sessions.js` file. I ran all the tests to make sure everything still works as expected.

I then added an *onError* setting. By default it's null, in which case Errors are thrown as normal. If a function is provided then that function is called instead with the Error object representing the error. Tests have been added for using onError with all existing error messages.

Example for onError:

```
sessions({
...
onError: function(err) {
// e.g. err.toString() -> "Error: Invalid cookie"
}
});
```