In response to the use of Promise return ctx.body, received '404 Not Found'.
See original GitHub issueIn response to the use of Promise return ctx.body, received ‘404 Not Found’. But my mongodb is showing that the data was written. This troubled me, look forward to help.
router.get('/api/login', function *(next) {
let request = this.request;
let response = this.response;
let params = request.query;
userInfo.set({
document: {
user: params.name,
password: params.password
}
})
.then(res => {
response.body = {
code: 0,
data: {
uid: res.uid,
}
};
})
.catch(err => {
response.body = {
code: 999999,
error: err
}
})
yield next;
})
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
koa.js returning 404 "Not Found" after signup, instead of the ...
I'm trying to get the jwt from body so i can make authenticated requests, but for some reason i keep on getting "Not...
Read more >next generation web framework for node.js
Return response Content‑Length as a number when present, or deduce from ctx.body when possible, or undefined. response.body. Page 28. 6/27/2017.
Read more >5.x API - Express.js
The function determines the file to serve by combining req.url with the provided root directory. When a file is not found, instead of...
Read more >Best Practices for Node.js Error-handling - Toptal
Developers working with Node.js sometimes find themselves writing not-so-clean code while handling all sorts of errors. This article will introduce you to ...
Read more >Resolving the JavaScript Promise Error "TypeError: Cannot ...
The response is then parsed into a JSON. This function is expected to return a Promise that should resolve to JSON data.
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
I’d personally suggest something like this:
Or omitting the try/catch portion and unifying your error-handling in middleware “upstream”.
just the last ctx.status = 200 ctx.body = {mes:‘fail’} do not works @tj