A workaround (maybe) for a really annoying issue with error handling and how parameters get passed to what
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
This commit is contained in:
parent
a89bcbb625
commit
9a073f6dca
1 changed files with 13 additions and 1 deletions
|
|
@ -83,7 +83,19 @@ export function Controller<T extends { new (...args: any[]): BaseController }>()
|
|||
console.log('[Controller.setup.<GET request>] Response:', res);
|
||||
console.log('[Controller.setup.<GET request>] 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue