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