From 9ced20fdccc1ac17511c0d621ddfcfa2081f28e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 8 Aug 2016 17:22:33 +0200 Subject: [PATCH] kvao: return 404 when expiring unknown key --- lib/connectors/kv-memory.js | 4 +++- test/kvao/expire.suite.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/connectors/kv-memory.js b/lib/connectors/kv-memory.js index 5ec97262..8cd92a46 100644 --- a/lib/connectors/kv-memory.js +++ b/lib/connectors/kv-memory.js @@ -109,7 +109,9 @@ function(modelName, key, ttl, options, callback) { if (!(key in store)) { return process.nextTick(function() { - callback(new Error('Cannot expire unknown key ' + key)); + var err = new Error('Cannot expire unknown key ' + key); + err.statusCode = 404; + callback(err); }); } diff --git a/test/kvao/expire.suite.js b/test/kvao/expire.suite.js index d444e545..ca66eb8a 100644 --- a/test/kvao/expire.suite.js +++ b/test/kvao/expire.suite.js @@ -38,7 +38,10 @@ module.exports = function(dataSourceFactory, connectorCapabilities) { it('returns error when key does not exist', function() { return CacheItem.expire('key-does-not-exist', 1).then( function() { throw new Error('expire() should have failed'); }, - function(err) { err.message.should.match(/key-does-not-exist/); }); + function(err) { + err.message.should.match(/key-does-not-exist/); + err.should.have.property('statusCode', 404); + }); }); }); };