Ошибка обработки: подключите ECONNREFUSED 127.0.0.1:5984 в nano couchdb - PullRequest
0 голосов
/ 18 июня 2020

Я настраиваю систему входа в систему с помощью nano, паспорта и couchdb. В основном все работает, но когда couchdb отключен, мне выдается эта ошибка:

(node:893) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5984
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
(node:893) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:893) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Мой код:

const LocalStrategy = require('passport-local').Strategy;
const nano = require('nano')('http://admin:password@localhost:5984');
const users = nano.use('users');
const bcrypt = require('bcrypt');

module.exports = function(passport) {
  passport.use(new LocalStrategy(
  function(username, password, done) {
    users.view('auth', 'auth', {'key': username, 'include_docs': true})
    .then(dbresponse => {
      if (dbresponse.rows.length === 1) {
        const user = dbresponse.rows[0].doc;
        bcrypt.compare(password, user.password, function(err, result) {
          if(result === true) {
            done(null, user)
          } else {
            done(null, false)
          }
        });
      } else {
        done(null, false);
      }
    })
  }
));
};

Я не могу остановить работу всего приложения, когда база данных не в сети. Я хотел бы как-нибудь исправить эту ошибку, но не могу понять, как это сделать.

...