Skip to content

Commit

Permalink
fix: delete cached promise when got fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 12, 2020
1 parent 5bfea13 commit 18d2c52
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/util/got/cache-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
},
Expand Down

0 comments on commit 18d2c52

Please sign in to comment.