diff --git a/classes/response.js b/classes/response.js index a746fe1..70a354a 100644 --- a/classes/response.js +++ b/classes/response.js @@ -25,8 +25,14 @@ class Response { return this.bodyBuffer; } - ejectFromCache() { - return fs.promises.unlink(this.cacheFilePath); + async ejectFromCache() { + try { + await fs.promises.unlink(this.cacheFilePath); + } catch (err) { + if (err.code !== 'ENOENT') { + throw err; + } + } } } diff --git a/test/tests.js b/test/tests.js index f45ef12..798bb01 100644 --- a/test/tests.js +++ b/test/tests.js @@ -96,6 +96,14 @@ describe('Cache tests', function() { res = await fetch(TWO_HUNDRED_URL); assert.strictEqual(res.fromCache, true); }); + + it('Does not error if rejecting from cache twice', async function() { + res = await fetch(TWO_HUNDRED_URL); + assert.strictEqual(res.fromCache, false); + + await res.ejectFromCache(); + await res.ejectFromCache(); + }); }).timeout(10000); describe('Data tests', function() {