lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.42k stars 489 forks source link

await or return missing on promiseHandler in express.hbs template #1506

Closed davidsaslawsky-trackinsight closed 8 months ago

davidsaslawsky-trackinsight commented 9 months ago

promiseHandler() returns a promise and should have either an await or a return here: https://github.com/lukeautry/tsoa/blob/master/packages/cli/src/routeGeneration/templates/express.hbs#L103C15-L103C29

The other templates (koa, hapi) are fine. I think it works on Express because it relies on the methods on the response object rather than on the end of the async handler.

Sorting

Expected Behavior

Current Behavior

It works as expected now but the code is a bit unsafe.

Possible Solution

- promiseHandler(controller, promise, response, {{successStatus}}, next);
+ return promiseHandler(controller, promise, response, {{successStatus}}, next);

or maybe replace promiseHandler() by an await on the controller method: there's the try / catch block calling next(err) anyway.

Context (Environment)

Version of the library: 5.1.1 Version of NodeJS: Node 18

github-actions[bot] commented 9 months ago

Hello there davidsaslawsky-trackinsight šŸ‘‹

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.šŸ‘€

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days