简体   繁体   English

NodeJS Q Promise捕获从未用护照JS调用

[英]Nodejs Q promise catch never called with passport js

I'm using the passport library for node to assist me in user signup. 我正在使用用于节点的通行证库来协助我进行用户注册。 I'm also using the 'Q' promise library to avoid the pyramid of doom as I go through several asynchronous steps. 在执行几个异步步骤时,我还使用了“ Q”承诺库来避免金字塔的厄运。

Everything works fine, until I throw an error from one of the promised steps. 一切正常,直到我从承诺的步骤之一抛出错误为止。 I would have assumed execution would drop into the .fail function, where I could handle the error and return out of passport with a failed signup. 我本.fail执行将落入.fail函数中,在该函数中我可以处理错误并通过失败的注册退出护照。 But for a reason that I don't understand, the .fail function never gets called. 但是由于我不明白的原因, .fail函数从未被调用。 Instead, I just get a stackdump in my browser window and in my console. 相反,我只是在浏览器窗口和控制台中获得了一个stackdump。

The controlling code is here: 控制代码在这里:

q.fcall(checkEmailIsFree({'email':email, 'username':username, 'password':password}))
.then(checkUsernameIsFree)
.then(registerUser)
.then(function (user) {
  if (user) {
    logDebug('REGISTERED: ' + email);
    return done(null, user);
  }
  else {
    logDebug('Could not register');
    return done(null, false);
  }
})
.fail(function (err) {
  logError('I never get here');
  return done(null, false);
})
.done();

And here's how I'm throwing, from within checkEmailIsFree 这是我在checkEmailIsFree

var error = new Error('Bad times. Email is in use: ' + email);
throw error;

Is there some overall express / node code somewhere that is set to fast dump out an exception somehow? 是否在某个地方设置了一些总体的express / node代码,以便以某种方式快速转储异常? Why isn't my catch being called? 为什么不叫我的渔获? What am I missing? 我想念什么?

I think done(onFulfilled, onRejected, onProgress) can help in this case. 我认为done(onFulfilled, onRejected, onProgress)在这种情况下可以提供帮助。 You can try: 你可以试试:

q.fcall(checkEmailIsFree({'email':email, 'username':username, 'password':password}))
.then(checkUsernameIsFree)
.then(registerUser)
.then(function (user) {
  if (user) {
    logDebug('REGISTERED: ' + email);
    return done(null, user);
  }
  else {
    logDebug('Could not register');
    return done(null, false);
  }
})
.done(undefined, function (err) {
  logError('Error!'); // used in case of reject
  return done(null, false);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM