how to redirect my login page when throw 400?

Highlighted
New Member
1 0 0

how to redirect my login page when throw 400? I catch the error.  an infinite redirect loop.

 

 

server.use(async (ctx, next) => {
    await next().catch(err => {
      const {status} = err
      if (status == 400) {
        ctx.redirect('/login')
      }
      console.log(err)
      ctx.app.emit('error', err, ctx);
    });
  })

router.get('*', verifyRequest(), async ctx => {
    console.log('other---')
    await handle(ctx.req, ctx.res);
    ctx.respond = false;
    ctx.res.statusCode = 200;
    const { shop, accessToken } = ctx.session;
  });

 

 

pcwang_0-1601135515379.png

 

0 Likes