koa-generic-session
Advanced tools
Comparing version 1.2.3 to 1.3.0
1.3.0 / 2014-11-22 | ||
================== | ||
* support options.errorHanlder, default throw set error | ||
1.2.3 / 2014-11-17 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -53,3 +53,5 @@ /**! | ||
* - [`genSid`] you can use your own generator for sid | ||
* - [`errorHanlder`] handler for session store get or set error | ||
*/ | ||
module.exports = function (options) { | ||
@@ -59,2 +61,3 @@ options = options || {}; | ||
var client = options.store || new MemoryStore(); | ||
var errorHandler = options.errorHandler || defaultErrorHanlder; | ||
@@ -143,3 +146,3 @@ var store = new Store(client, { | ||
debug('get session error: ', err.message); | ||
throw err; | ||
errorHandler(err, 'get', this); | ||
} | ||
@@ -204,2 +207,3 @@ } | ||
debug('set session error: ', err.message); | ||
errorHandler(err, 'set', this); | ||
} | ||
@@ -225,3 +229,2 @@ } | ||
yield *next; | ||
if (result) yield *refreshSession.call(this, this.session, result.originalHash); | ||
@@ -309,1 +312,6 @@ } | ||
module.exports.MemoryStore = MemoryStore; | ||
function defaultErrorHanlder (err, type, ctx) { | ||
err.name = 'koa-generic-session ' + type + ' error'; | ||
throw err; | ||
} |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/generic-session", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"keywords": ["koa", "middleware", "session"], | ||
@@ -8,0 +8,0 @@ "author": "dead_horse <dead_horse@qq.com>", |
@@ -91,2 +91,3 @@ generic-session | ||
* `allowEmpty`: allow generation of empty sessions | ||
* `errorHandler(err, type, ctx)`: `Store.get` and `Store.set` will throw in some situation, use `errorHandle` to handle these errors by yourself. Default will throw. | ||
@@ -93,0 +94,0 @@ * Store can be any Object that has the methods `set`, `get`, `destroy` like [MemoryStore](https://github.com/koajs/koa-session/blob/master/lib/store.js). |
@@ -77,6 +77,3 @@ /**! | ||
it('should ignore session error when store.set error', function (done) { | ||
mm(commonApp.store, 'set', function *() { | ||
throw new Error('mock set error'); | ||
}); | ||
it('should handler session error when store.set error', function (done) { | ||
request(commonApp) | ||
@@ -87,7 +84,10 @@ .get('/session/get') | ||
.expect(/2/, function () { | ||
mm(commonApp.store, 'set', function *() { | ||
throw new Error('mock set error'); | ||
}); | ||
request(commonApp) | ||
.get('/session/nothing') | ||
.get('/session/get') | ||
.set('cookie', cookie) | ||
.expect(200) | ||
.expect(/1/, done); | ||
.expect(500) | ||
.expect(/Internal Server Error/, done); | ||
}); | ||
@@ -146,7 +146,4 @@ }); | ||
it('should ignore session error when store.set error', function (done) { | ||
mm(deferApp.store, 'set', function *() { | ||
throw new Error('mock set error'); | ||
}); | ||
request(deferApp) | ||
it('should handler session error when store.set error', function (done) { | ||
request(commonApp) | ||
.get('/session/get') | ||
@@ -156,7 +153,10 @@ .set('cookie', cookie) | ||
.expect(/2/, function () { | ||
request(deferApp) | ||
.get('/session/nothing') | ||
mm(commonApp.store, 'set', function *() { | ||
throw new Error('mock set error'); | ||
}); | ||
request(commonApp) | ||
.get('/session/get') | ||
.set('cookie', cookie) | ||
.expect(200) | ||
.expect(/1/, done); | ||
.expect(500) | ||
.expect(/Internal Server Error/, done); | ||
}); | ||
@@ -163,0 +163,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43291
1072
145