From a70a62ccf90de41d7d200cae1b24418e9535f006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 21 Feb 2026 18:56:53 -0500 Subject: [PATCH] refactor: shorter check --- src/plugins/hooks.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index d9addd2b18..cdd30951f1 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -181,15 +181,13 @@ async function fireActionHook(hook, hookList, params) { return; } for (const hookObj of hookList) { - if (!isHookValid(hook, hookObj)) { - continue; - } - - try { - // eslint-disable-next-line - await hookObj.method(params); - } catch (err) { - winston.error(`[plugins] Error in hook ${hookObj.id}@${hookObj.hook} \n${err.stack}`); + if (isHookValid(hook, hookObj)) { + try { + // eslint-disable-next-line + await hookObj.method(params); + } catch (err) { + winston.error(`[plugins] Error in hook ${hookObj.id}@${hookObj.hook} \n${err.stack}`); + } } } } @@ -255,16 +253,14 @@ async function fireResponseHook(hook, hookList, params) { return; } for (const hookObj of hookList) { - if (!isHookValid(hook, hookObj)) { - continue; - } + if (isHookValid(hook, hookObj)) { + // Skip remaining hooks if headers have been sent + if (params.res.headersSent) { + return; + } - // Skip remaining hooks if headers have been sent - if (params.res.headersSent) { - return; + // eslint-disable-next-line no-await-in-loop + await hookObj.method(params); } - - // eslint-disable-next-line no-await-in-loop - await hookObj.method(params); } }