Getting 404 or 204 as responses; need guidance on using async / await
See original GitHub issueHello!
Total Koa newbie here, also new to the async/await syntax. In the post request below i was wondering how I can properly return the completed
variable and attach it to ctx.body
.
router.post('/resume', async (ctx) => {
await form.parse(ctx.req, (err, fields, files) => {
return sendMail(fields.candidateName, files.attachment)
.then((completed) => {
return completed;
});
});
})
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
node.js - I am getting 404 error and 204 error when ...
What i have tried: Frontend: I tried with adding headers to my axios request. I console logged the data and it seems perfectly...
Read more >Should I return a 204 or a 404 response when a resource is ...
HTTP 204 means that something was found, but it's empty. For instance, imagine that you're serving log files through HTTP, with the requests ......
Read more >HTTP/1.1: Status Code Definitions
Use of this response code is not required and is only appropriate when the response would otherwise be 200 (OK). 10.2.5 204 No...
Read more >Minimal APIs quick reference - Microsoft Learn
Provides an overview of minimal APIs in ASP.NET Core.
Read more >Using Express.js Routes for Promise-based Error Handling
And now let's use it in our users router in async / await style with direct response manipulation: router.get('/:id/profilePic', async function (req, res) ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rainesinternationaldev
form.parse
doesn’t return it a promise from what I can tell. It seems to use an event based system. Try this:@rainesinternationaldev Thanks! 😃 About the moving of reject and resolve - I’d be a bit careful about that as this will now error to the console if you have more than one upload in your form (as the Promise will resolve multiple times).
Nope, a response is triggered when the returned promise resolves. Also, now you can just set
ctx.body
instead of appending to it as your code is for one upload only.