如果我要返回自定义错误需要怎么配置呢

来源:3-15 jwt-加密用户信息

qq_假正经_6

2020-07-22

写回答

1回答

双越

2020-07-22

看下文档 https://www.npmjs.com/package/koa-jwt ,在其中搜索“Custom 401 handling”,就这段代码

// Custom 401 handling if you don't want to expose koa-jwt errors to users
app.use(function(ctx, next){
  return next().catch((err) => {
    if (401 == err.status) {
      ctx.status = 401;
      ctx.body = 'Protected resource, use Authorization header to get access\n';
    } else {
      throw err;
    }
  });
});


0
1
qq_假正经_6
非常感谢!
2020-08-08
共1条回复

Node.js+Koa2框架生态实战 - 从零模拟新浪微博

用 Koa2 做真正的实战项目,不再只是增删改查的小白工程师

964 学习 · 388 问题

查看课程