如果我要返回自定义错误需要怎么配置呢
来源:3-15 jwt-加密用户信息

qq_假正经_6
2020-07-22
写回答
1回答
-
看下文档 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; } }); });
012020-08-08
相似问题