From 2872ca8aec5c5b650ef24d4d6252795160f11f98 Mon Sep 17 00:00:00 2001 From: linbuxiao <56839018+linbuxiao@users.noreply.github.com> Date: Sat, 27 Nov 2021 16:32:39 +0800 Subject: [PATCH] fix: cache next error not catch (#8361) --- lib/middleware/cache/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/middleware/cache/index.js b/lib/middleware/cache/index.js index e12f5e519..9aa7628b3 100644 --- a/lib/middleware/cache/index.js +++ b/lib/middleware/cache/index.js @@ -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();