Send get method some cases return Not Found #1553
-
I try to write an simple jwt api with mongodb, the router.use('/user', async (ctx, next) => {
// do sth. and run next
}, async (ctx) => {
try {
// here do some mongodb query, and get right result
ctx.body = {
// I want to return query result here, but return 'Not Found' and 404
}
} catch (e) {}
}) return 'Not Found' and 404 in postman But I write a simple router.get('/test', async (ctx, next) => {
ctx.body = "456"
await next()
}, async (ctx) => {
ctx.body += "1234"
}) I can get "4561234" in postman. Confused. {
"dependencies": {
"crypto-js": "^4.0.0",
"jsonwebtoken": "^8.5.1",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0",
"koa-router": "^10.0.0",
"mongoose": "^5.12.13"
}
} Tks for reading my poor English |
Beta Was this translation helpful? Give feedback.
Answered by
jonathanong
Jun 28, 2021
Replies: 2 comments
-
you should ask this in the koa-router repository, not here |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jonathanong
-
if you want router.get('/test', async (ctx, next) => {
await next()
ctx.body += "456"
}, async ctx => {
ctx.body = "123"
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should ask this in the koa-router repository, not here