【问题标题】:How to redirect on error with Everyauth / Node.js如何使用 Everyauth / Node.js 重定向错误
【发布时间】:2011-10-10 12:51:52
【问题描述】:

当尝试使用错误的用户/密码组合进行身份验证时,everyauth 总是在每个 module.js:352 处引发错误

./node_modules/everyauth/lib/modules/everymodule.js:352
  throw err;
  ^
Error: Name or password is incorrect.
    at gen_err (./node_modules/nano/error.js:93:43)
    at Object.couch (./node_modules/nano/error.js:102:48)
    at Request.callback (./node_modules/nano/nano.js:147:26)
    at Request.<anonymous> (./node_modules/nano/node_modules/request/main.js:314:21)
    at Request.emit (events.js:64:17)
    at IncomingMessage.<anonymous> (./node_modules/nano/node_modules/request/main.js:295:19)
    at IncomingMessage.emit (events.js:81:20)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at Socket.ondata (http.js:1231:22)
    at Socket._onReadable (net.js:677:27)

这是我的验证码:

.authenticate( function (login, password) {
    var promise = this.Promise();
  var auth = nano.auth(login, password, function(error, document, headers) {
    if (error) {
        return promise.fail(error);
    } else if (document.userCtx.name === login && document.ok === true) {
      console.log(login);
      var user = nano.user(login, function(error, document, headers) {
        console.log(document);
        return promise.fulfill(document);
      });
    }
  });
  return promise;
})

使用正确的用户/密码可以正常工作并转发到“loginSuccessRedirect”。但是由于抛出错误,Node 服务器总是挂起并崩溃,而不是重定向到 404 或 401。

【问题讨论】:

  • 你解决过这个问题吗?遇到同样的问题,只要 promise 失败,就抛出异常,node 关闭
  • 不,我选择了 promise.fulfill。
  • 好的,我得照做,谢谢

标签: javascript authentication node.js


【解决方案1】:

return promise.fail(error); 错误。

API 声明应该用Array 的错误来履行承诺,所以

promise.fulfill([error])

会工作

【讨论】:

  • 自述文件中有一些使用 .fail() 的示例,它也在 Promise 库中。它有效,只是重定向不起作用。完成有错误的事情有点矛盾,不是吗?
猜你喜欢
  • 2012-11-22
  • 2012-08-09
  • 2023-03-25
  • 2012-11-26
  • 2017-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-20
相关资源
最近更新 更多