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); + } + } }); });