-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app.httpclient.on如何实现抛出异常被外部统一捕获 #3321
Labels
Comments
看来对 Node 的 callback error 处理不是很熟悉啊,在一个回调里面抛错,必然捕获不到啊。 你的原始需求是啥 |
app.httpclient.on('response', result => {
if (result.res.code < 0) { app.logger.error(new Error('error')); }
}); 改为直接打错误,这个已经不在洋葱圈里了。 |
Hello @bymaxchen. Please provide a reproducible example following the instruction. Issues labeled by @bymaxchen,请根据这个说明提供最小可复现代码。 如果在 7 天内没有进展会被自动关闭。 |
@atian25 |
|
@popomore 好的,谢谢解答。 |
// app/extend/context.js
module.exports = {
async sendRPC(url, options) {
const result = await this.curl(url, options);
if (xxxx) throw new Error('xxxx');
return result;
}
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
app.js
app.httpclient.on('response', result => { if (result.res.code < 0) { throw new Error('error'); } });
middleware/error-handler.js
try { yield next; } catch (err) { console.log(err) }
这里错误无法被捕获。进程反而会crash,抛出uncaughtException。
The text was updated successfully, but these errors were encountered: