Skip to content
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

UnhandledPromiseRejectionWarning #59

Open
jinceon opened this issue Feb 8, 2018 · 4 comments
Open

UnhandledPromiseRejectionWarning #59

jinceon opened this issue Feb 8, 2018 · 4 comments

Comments

@jinceon
Copy link

jinceon commented Feb 8, 2018

只要出现支付失败,就会提示这个warning。
应该怎样加catch?

@wbget
Copy link

wbget commented Feb 11, 2018

+1,我也在外层catch不到。

@supersheep
Copy link
Owner

promisfy的方法需要在调用前只用 await 修饰才能被 try/catch 到,也可以使用传递 callback 函数的方式来处理错误。

@jinceon
Copy link
Author

jinceon commented Jul 11, 2018

payment.refund({
  out_trade_no: "kfc001",
  out_refund_no: 'kfc001_refund',
  total_fee: 10 * 100,
  refund_fee: 10 * 100
}, function(err, result){
  /**
   * 微信收到正确的请求后会给用户退款提醒
   * 这里一般不用处理,有需要的话有err的时候记录一下以便排查
   */
});

nodejs 8,9,10,应该是6.6以上的都会吧。
就这个退款例子来说,如果这样写代码,一定会报UnhandledPromiseRejectionWarning。

我项目里是用 co + yield 来做异步流程控制的。

co(function*(){
    let result = yield payment.refund({
  out_trade_no: "kfc001",
  out_refund_no: 'kfc001_refund',
  total_fee: 10 * 100,
  refund_fee: 10 * 100
})
}).catch(function(err){
    /*注意这里的err,只有err.name, data已经丢了。
     参考 Payment.prototype.validate里
      error = new Error();
      error.name = 'InvalidSignature';
      callback(error, data);
    */
})

@jinceon
Copy link
Author

jinceon commented Jul 13, 2018

我觉得 Payment.js里最后一段 Promisify 似乎不好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants