我如何吞下错误,例如......错误:抛出非错误:“没有找到 cookie”在 Koa 中没有 500 响应

问题描述

我有以下代码...

verifyToken(ctx){
        return new Promise(async (res,rej)=>{
            const cookie = ctx.cookies.get("userInfo");
            if(cookie == null) return rej("No cookie found"); // Cookie isn't set...
            ...
        }
}
async checkToken(ctx,next){
    await this.verifyToken(ctx).catch(err=>`The verification Failed ${err}`);
    await next();
}
mainApp.use(auth.checkToken.bind(auth));

但是当我跑步时我得到...

  Error: non-error thrown: "No cookie found"
      at Object.onerror (/.../node-se/node_modules/koa/lib/context.js:119:31)
      at onerror (/.../node-se/node_modules/koa/lib/application.js:165:32)
      at processticksAndRejections (node:internal/process/task_queues:94:5)

和 500 响应。我想要的行为是注意缺少 cookie 并继续前进。在没有 500 响应的情况下,我如何吃掉这个错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)