Seeing if by using pp.use instead of pp.get I get the next function as expected that would allow for proper error handling withn the decorators
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 43s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 43s
This commit is contained in:
parent
614041d6ca
commit
338e67e4d2
1 changed files with 5 additions and 7 deletions
|
|
@ -74,17 +74,15 @@ export function Controller<T extends { new (...args: any[]): BaseController }>()
|
|||
// Get the 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) => target.prototype[method](req, res, next);
|
||||
}
|
||||
|
||||
// Get the path
|
||||
const path = Reflect.getMetadata(GET_METADATA_KEY, target.prototype, method);
|
||||
|
||||
// Bind the method to the class instance
|
||||
app.get(path, fn.bind(controller));
|
||||
app.use((req, res, next) => {
|
||||
if(req.path === path && req.method === 'GET') {
|
||||
fn.bind(controller)(req, res, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Loop over all the methods in the decorated class looking for methods that use the POST decorator
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue