cookie-sessions icon indicating copy to clipboard operation
cookie-sessions copied to clipboard

CoffeeScript rewrite + Added an onError setting to the initial call

Open hiddentao opened this issue 14 years ago • 0 comments

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"
        }
    });

hiddentao avatar Jan 13 '12 01:01 hiddentao