From 62ba90a998fca3e730c5417efdbf85d4b082a990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=A9monic?= Date: Fri, 7 Sep 2018 19:14:18 +0200 Subject: [PATCH] Reject nullable value from cache - Get cache resolve promise only when value is not null - Remove new keyword from Promise.reject usage --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2f18e36..4b00cf9 100644 --- a/index.js +++ b/index.js @@ -19,10 +19,13 @@ const CacheStore = { return AsyncStorage.getItem(exprKey).then((expiry) => { if (expiry && currentTime() >= parseInt(expiry, 10)){ AsyncStorage.multiRemove([exprKey, theKey]); - return new Promise.reject(null); + return Promise.reject(null); } return AsyncStorage.getItem(theKey).then((item) => { - return Promise.resolve(JSON.parse(item)); + if (item) { + return Promise.resolve(JSON.parse(item)); + } + return Promise.reject(null); }); }); }, @@ -48,7 +51,7 @@ const CacheStore = { const exprKey = CACHE_EXPIRATION_PREFIX + key; return AsyncStorage.getItem(exprKey).then((expiry) => { var expired = expiry && currentTime() >= parseInt(expiry, 10); - return expired ? Promise.resolve() : new Promise.reject(null); + return expired ? Promise.resolve() : Promise.reject(null); }); },