From 868a8aaadb21265d802b07917cf603f05fcdd3f0 Mon Sep 17 00:00:00 2001 From: Alan Bridgeman Date: Tue, 24 Jun 2025 07:22:34 -0500 Subject: [PATCH] Attempting change to Controller's setup to see if it fixes error handling problem --- src/decorators/Controller.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/decorators/Controller.ts b/src/decorators/Controller.ts index c8545d5..e7b4197 100644 --- a/src/decorators/Controller.ts +++ b/src/decorators/Controller.ts @@ -1,4 +1,4 @@ -import { Application, NextFunction } from 'express'; +import { Application, Request, Response, NextFunction } from 'express'; import { BaseController } from '../controllers/BaseController'; @@ -72,7 +72,13 @@ export function Controller() .filter((method) => Reflect.getMetadata(GET_METADATA_KEY, target.prototype, method)) .map((method) => { // Get the method - const fn = target.prototype[method]; + let fn = target.prototype[method]; + + // If `fn` is the two parameter variant force it to be a three parameter variant + // This is because of how error handling is done in the framework (based on how Express does it) + if(fn.length === 2) { + fn = (req: Request, res: Response, next: NextFunction) => fn(req, res, next); + } // Get the path const path = Reflect.getMetadata(GET_METADATA_KEY, target.prototype, method);