Skip to content

Commit 9ced20f

Browse files
committed
kvao: return 404 when expiring unknown key
1 parent 83a2826 commit 9ced20f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/connectors/kv-memory.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ function(modelName, key, ttl, options, callback) {
109109

110110
if (!(key in store)) {
111111
return process.nextTick(function() {
112-
callback(new Error('Cannot expire unknown key ' + key));
112+
var err = new Error('Cannot expire unknown key ' + key);
113+
err.statusCode = 404;
114+
callback(err);
113115
});
114116
}
115117

test/kvao/expire.suite.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
3838
it('returns error when key does not exist', function() {
3939
return CacheItem.expire('key-does-not-exist', 1).then(
4040
function() { throw new Error('expire() should have failed'); },
41-
function(err) { err.message.should.match(/key-does-not-exist/); });
41+
function(err) {
42+
err.message.should.match(/key-does-not-exist/);
43+
err.should.have.property('statusCode', 404);
44+
});
4245
});
4346
});
4447
};

0 commit comments

Comments
 (0)