-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Await apiHandler to handle error in try/catch #1602
Await apiHandler to handle error in try/catch #1602
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello there VincentClair 👋
Thank you and congrats 🎉 for opening your first PR on this project.✨
We will review the following PR soon! 👀
@@ -103,7 +103,7 @@ export function RegisterRoutes(app: Router) { | |||
const controller = new {{../name}}(); | |||
{{/if}} | |||
|
|||
templateService.apiHandler({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can always await
@jackey8616
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, but function must be always async: we could replace condition {{#if ../../iocModule}}async {{/if}}
line 82 by async directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was the ultimate goal, while still making ts not complain about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can always await @jackey8616
Yes, I think that's good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
try { | ||
const promise = this.buildPromise(methodName, controller, validatedArgs); | ||
const data = await Promise.resolve(promise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is Promise.resolve mandatory : promise ca be waited directly, no? const data = await promise;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, remove it, assuming this.buildPromise never returns anything but a Promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
6b8c611
to
03efb05
Compare
Hello @WoH @jackey8616, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, lgtm 🚀
When can we expect a new release with this fix included? Much appreciated |
All Submissions:
Closing issues
closes #1598
Test plan
Checks that a controller method without
async
keyword throwing an error is caught.The real problem is if method is not a promise (
async
keyword), and error throw immediately when building promise, server is no more responding, and we get a time out (actually 5sec in tests).The problem could resolve in two ways :
buildPromise
int the try/catchtsoa/packages/runtime/src/routeGeneration/templates/express/expressTemplateService.ts
Line 41 in efdb468
apiHandler
to be resolved on generated templatetsoa/packages/cli/src/routeGeneration/templates/express.hbs
Line 106 in efdb468
I have chosen to apply both, as I think code will be more robust.