question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Koa2: setting ctx.status prior to ctx.redirect call does not yield any effect.

See original GitHub issue

Is this a bug?

per documentation https://github.com/koajs/koa/blob/v2.x/docs/api/response.md#responseredirecturl-alt

if i set ctx.status prior ctx.redirect call my response status should be set to what ever is i specify it to, but this does not happen in my case. I have middle wear that redirects visitor for any path that does not fall under exception if they do not have authenticated session.

        if (authRequired && !ctx.isAuthenticated()) {
            ctx.status = authConfig.authRequiredRedirect.statusCode;
            ctx.redirect(authConfig.authRequiredRedirect.path);
        }

image

Am I missing something?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gnrlbzikcommented, Nov 24, 2016

yeah, i am doing it wrong. i will close both : ) thanks for help

0reactions
gnrlbzikcommented, Nov 24, 2016

Maybe i am doing this wrong. Possibly my understanding of this subject is off. let me consult web for a bit.

Original goal was to respond to none-auth user with 401 and redirect them to login page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Koa - next generation web framework for node.js
If an error is in the req/res cycle and it is not possible to respond to the client, the Context instance is also...
Read more >
Koa's `ctx.status` not getting sent to client - Stack Overflow
Looking at the Koa code, it has specific handling for ENOENT (which is the error that gets thrown when a file doesn't exist):...
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-router: Router Middleware for Koa - Morioh
session middleware will run before authorize router .use(session()) ... router.all('/login', ctx => { ctx.redirect('/sign-in'); ctx.status = 301; });.
Read more >
Efficacy of sCOMP and sCTX-I in Diagnosis of Knee ...
Only CTX-I was also able to distinguish between K–L grades I and II, ... Radiographs scored as grade 0 (normal) showed no radiographic ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found