From 943cbe5cb8e1ca0d2fc10dd04d6c300d60e34da3 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 8 Apr 2020 21:57:49 +0200 Subject: [PATCH] Return rejected promise and don't set cache if key or value is null. --- seasoned_api/src/cache/redis.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seasoned_api/src/cache/redis.js b/seasoned_api/src/cache/redis.js index c7b1266..df206bb 100644 --- a/seasoned_api/src/cache/redis.js +++ b/seasoned_api/src/cache/redis.js @@ -11,7 +11,7 @@ class Cache { return new Promise((resolve, reject) => { client.get(key, (error, reply) => { if (reply == null) { - reject() + return reject() } resolve(JSON.parse(reply)) @@ -27,6 +27,9 @@ class Cache { * @returns {Object} */ set(key, value, timeToLive = 10800) { + if (value == null || key == null) + return null + const json = JSON.stringify(value); client.set(key, json, (error, reply) => { if (reply == 'OK') {