您如何捕获 PouchDB 创建时的错误?
How do you catch errors on PouchDB creation?
我不知道在哪里可以捕捉到访问 pouch 中的远程 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 我不知道我应该如何捕捉数据库创建错误。
您可以 db.info()
然后验证请求是否有效。
我在尝试将本地数据库复制到不存在的远程数据库时遇到了类似的错误。我的错误被复制事件的错误处理程序捕获:
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
});
这可能会对遇到类似问题的其他人有所帮助。
我不知道在哪里可以捕捉到访问 pouch 中的远程 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 我不知道我应该如何捕捉数据库创建错误。
您可以 db.info()
然后验证请求是否有效。
我在尝试将本地数据库复制到不存在的远程数据库时遇到了类似的错误。我的错误被复制事件的错误处理程序捕获:
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
});
这可能会对遇到类似问题的其他人有所帮助。