Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix try catch bug of get & update the test

  • Loading branch information...
commit 0d8dd5b108fe173ec070dd83511ba1256b97e9fd 1 parent 0c6155d
heyiyu.pt_52624 authored committed
Showing with 16 additions and 10 deletions.
  1. +8 −7 lib/connect-redis.js
  2. +8 −3 test.js
View
15 lib/connect-redis.js
@@ -85,20 +85,21 @@ module.exports = function(connect){
* @param {Function} fn
* @api public
*/
-
RedisStore.prototype.get = function(sid, fn){
sid = this.prefix + sid;
debug('GET "%s"', sid);
this.client.get(sid, function(err, data){
if (err) return fn(err);
+ if (!data) return fn();
+ var result;
+ data = data.toString();
+ debug('GOT %s', data);
try {
- if (!data) return fn();
- data = data.toString();
- debug('GOT %s', data);
- fn(null, JSON.parse(data));
+ result = JSON.parse(data);
} catch (err) {
- fn(err);
- }
+ return fn(err);
+ }
+ return fn(null, result);
});
};
View
11 test.js
@@ -15,12 +15,12 @@ store.client.on('connect', function(){
store.set('123', { cookie: { maxAge: 2000 }, name: 'tj' }, function(err, ok){
assert.ok(!err, '#set() got an error');
assert.ok(ok, '#set() is not ok');
-
+
// #get()
store.get('123', function(err, data){
assert.ok(!err, '#get() got an error');
assert.deepEqual({ cookie: { maxAge: 2000 }, name: 'tj' }, data);
-
+
// #set null
store.set('123', { cookie: { maxAge: 2000 }, name: 'tj' }, function(){
store.destroy('123', function(){
@@ -29,6 +29,11 @@ store.client.on('connect', function(){
store_alt.client.end();
});
});
- })
+ throw new Error('Error in fn');
+ });
});
});
+
+process.once('uncaughtException', function (err) {
+ assert.ok(err.message === 'Error in fn', '#get() catch wrong error');
+});
Please sign in to comment.
Something went wrong with that request. Please try again.