fix: cache next error not catch (#8361)

This commit is contained in:
linbuxiao 2021-11-27 16:32:39 +08:00 committed by GitHub
parent 44cfbc4d79
commit 2872ca8aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -114,7 +114,13 @@ module.exports = function (app) {
// Doesn't hit the cache? We need to let others know!
await globalCache.set(controlKey, '1', config.cache.requestTimeout);
await next();
try {
await next();
} catch (e) {
await globalCache.set(controlKey, '0', config.cache.requestTimeout);
throw e;
}
if (ctx.response.get('Cache-Control') !== 'no-cache' && ctx.state && ctx.state.data) {
ctx.state.data.lastBuildDate = new Date().toUTCString();