Receiving 404 "Not Found" but i'm setting ctx.response.body = token
See original GitHub issueHi!
I keep getting 404 "Not Found"
while i’ve already set ctx.response.body = token
*where toke
is a valid token
in my tests (with supertest
& in postman
).
Is there a way to publish the token and override the “Not found” message?
Here is how i’m making the token
const signUp = async (ctx, next) => {
const bodyInfo = await ctx.request.body;
if(!bodyInfo.username || !bodyInfo.password) {
ctx.status = 402;
ctx.body = "Error, username and password must be provided!";
}
const userInst = new User(bodyInfo);
userInst.save(async(err, user) => {
if(err) { return next(err); }
const token = tokenForUser(user);
ctx.body = token; //- <-- Passing the token.
return next();
});
};
export { signUp, signIn };
the route that i hit to get this middleware is
router.post('/signup', signUp);
//- oddly enough
router.post('/signup', signUp, async (ctx, next) => {
const res = await ctx.response;
//- returns a lot of good stuff including `token` but can't publish token outside.
console.log(res);
I wish to override “Not Found” message and the whole ctx.response
cause i get really long weird pre made 404s for a route that is preset.
Here is my stack trace.
1) Authentication signs up:
Error: expected 200 "OK", got 404 "Not Found"
at Test._assertStatus (node_modules/supertest/lib/test.js:266:12)
at Test._assertFunction (node_modules/supertest/lib/test.js:281:11)
at Test.assert (node_modules/supertest/lib/test.js:171:18)
at assert (node_modules/supertest/lib/test.js:131:12)
at node_modules/supertest/lib/test.js:128:5
at Test.Request.callback (node_modules/superagent/lib/node/index.js:631:3)
at IncomingMessage.<anonymous> (node_modules/superagent/lib/node/index.js:795:18)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Please help and if i’m missing anything i asked this question on stackoverflow here.
Thank you.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 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 >404 error using node.js checkoutAPI - Square Developer
I'm trying to use square hosted checkout for my pizza business. It looks as though the data I'm sending is valid, as I...
Read more >Responses | Strapi Documentation
Whenever a stream is set as the response body, .onerror is automatically added as a listener to the error event to catch any...
Read more >Sending Response with Koa - Medium
We can send response status codes by setting the status code value to the responbse.status property. ... ctx.status = 202; ctx.body = 'accepted';...
Read more >KOA route return 404 not found - Shopify Community
Bumping, I followed the tutorial and setup my route like so: //server.js router.get('/products', verifyRequest(), async (ctx) => {¬ await handle ...
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
this is wrong, use userInst.save like a promise
if your database manager dont support promises, build your own promise
in my case, it was about calling
await next()
at the end of the middleware.