From 9a073f6dca1c8a2f290926c04e0aacfb1834978f Mon Sep 17 00:00:00 2001 From: Alan Bridgeman Date: Tue, 24 Jun 2025 12:19:45 -0500 Subject: [PATCH] A workaround (maybe) for a really annoying issue with error handling and how parameters get passed to what --- src/decorators/Controller.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/decorators/Controller.ts b/src/decorators/Controller.ts index 60e02b1..8af64b3 100644 --- a/src/decorators/Controller.ts +++ b/src/decorators/Controller.ts @@ -83,7 +83,19 @@ export function Controller() console.log('[Controller.setup.] Response:', res); console.log('[Controller.setup.] Next:', next); - return await fn.bind(controller)(req, res, next); + try { + return await fn.bind(controller)(req, res, next); + } + catch(error) { + if(typeof next !== 'undefined') { + next(error); + return; + } + else { + // Because next is undefined and we still want to have Express handle the error we reject the promise + return Promise.reject(error); + } + } }); });