Skip to content

Commit 40d122d

Browse files
authored
Merge pull request #2 from martinzuern/error-handling
Added config option for error handling
2 parents 3ab3dca + 876ba47 commit 40d122d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var SecureStore = require('secure-store-redis');
99
var store = new SecureStore({
1010
namespace: 'myApp:store',
1111
secret: 'quacks like a duck',
12+
errorOnNotFound: true, //optional; will cb error if data can't be found
1213
redis: {
1314
host: 'localhost', // optional
1415
port: 6379, // optional

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function SecureStore(cfg) {
1414
this.namespace = cfg.namespace || 'secure-store-redis';
1515
this.secret = cfg.secret;
1616

17+
this.errorOnNotFound = cfg.errorOnNotFound || true;
18+
1719
if (! cfg.redis) { cfg.redis = {}; }
1820
//this.db = cfg.db || 0;
1921

@@ -71,7 +73,11 @@ SecureStore.prototype.get = function (postfix, key, cb) {
7173
if (err) {
7274
cb(err);
7375
} else if (typeof reply !== 'string') {
74-
cb('record not found for key: ' + key);
76+
if (this.errorOnNotFound) {
77+
return cb('record not found for key: ' + key);
78+
} else {
79+
return cb(null, null);
80+
}
7581
} else {
7682

7783
var data;

0 commit comments

Comments
 (0)