diff --git a/__tests__/plugins/cache.test.js b/__tests__/plugins/cache.test.js index b757b8a..0eaa677 100644 --- a/__tests__/plugins/cache.test.js +++ b/__tests__/plugins/cache.test.js @@ -45,6 +45,13 @@ describe("plugin: cache", () => { expect(self.LibResilientPlugins[0].name).toEqual('cache'); }); + test("it should error out if resource is not found", () => { + require("../../plugins/cache.js"); + + expect.assertions(1) + return expect(self.LibResilientPlugins[0].fetch('https://resilient.is/test.json')).rejects.toThrow(Error) + }); + test("it should stash successfully", () => { require("../../plugins/cache.js"); expect.assertions(7); diff --git a/plugins/cache.js b/plugins/cache.js index ec323b6..eb16b8c 100644 --- a/plugins/cache.js +++ b/plugins/cache.js @@ -29,7 +29,7 @@ return cache.match(url) }) .then((response) => { - if (typeof response === 'undefined') { + if ((typeof response === 'undefined') || (response === null) ) { throw new Error('Resource not found in cache'); } else { var msg = 'retrieved cached headers:'