koa1里多错误的捕获,有些问题 ,有什么更好的方法?
发布于 16 小时前 作者 wangshiyang3035884 90 次浏览 来自 问答

//问题1: 捕获错误 代码报错,只支持构造器方法 app.use(‘error’, function(err){ console.log(err.status); if (this.status == 404) { yield this.render(‘404’, { message : this.message }); } else if(this.status == 500){ yield this.render(‘500’, { message : this.message }); } }); // 问题2 只能捕捉地址栏路径错误,捕捉不到代码错误 app.use(function *notFound(next, ctx) { if (this.status == 404) { yield this.render(‘404’, { message : this.message }); } else if(this.status == 500){ yield this.render(‘500’, { message : this.message }); }else { yield next; } });

1 回复

可以试试try catch啊

回到顶部