你如何捕获PouchDB创建错误?

时间:2016-07-12 00:49:20

标签: pouchdb

我无法弄清楚我在哪里可以捕获到小袋中访问远程couchdb的失败尝试。例如:

var testPouchDB = new PouchDB('http://remotedb-url/non-existant-db-name);

如果用户由于权限而无法创建该数据库,则会抛出此错误:

CustomPouchError {status: 401, name: "unauthorized", message: "Name or password is incorrect.", error: true, reason: "You are not a server admin."}

我的构建设置可能隐藏在抛出的位置,正如开发工具在undefined:1所说的那样,但也来自API docs我无法弄清楚我是怎样的#&# 39;我应该捕获数据库创建错误。

2 个答案:

答案 0 :(得分:1)

您可以执行db.info(),然后验证请求是否有效。

答案 1 :(得分:0)

尝试将本地数据库复制到不存在的远程数据库时,我发现了类似的错误。我的错误是在复制事件的错误处理程序中捕获的:

const remoteUserDB = new PouchDB('http://remote-url/db-name', {
  auth: ...
});

localDB.replicate.to(remoteUserDB, {
  live: true,
  retry: true
}).on('error', function (err) {
  console.log('error: ', err);  // <-- Caught here
});

这可能有助于其他有类似问题的人。