From 18d2c52327b3a275401f5beec2bd9d3e619ccb2f Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 12 Mar 2020 15:59:03 +0100 Subject: [PATCH] fix: delete cached promise when got fails --- lib/util/got/cache-get.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/util/got/cache-get.ts b/lib/util/got/cache-get.ts index 60351f4d21..8ba6ae86e2 100644 --- a/lib/util/got/cache-get.ts +++ b/lib/util/got/cache-get.ts @@ -8,7 +8,7 @@ import { clone } from '../clone'; // istanbul ignore next export default create({ options: {}, - handler: (options, next) => { + handler: async (options, next) => { if (!global.repoCache) { return next(options); } @@ -26,10 +26,16 @@ export default create({ if (!global.repoCache[cacheKey] || options.useCache === false) { global.repoCache[cacheKey] = next(options); } - return global.repoCache[cacheKey].then(response => ({ - ...response, - body: clone(response.body), - })); + try { + const response = await global.repoCache[cacheKey]; + return { + ...response, + body: clone(response.body), + }; + } catch (err) { + delete global.repoCache[cacheKey]; + throw err; + } } return next(options); }, -- GitLab