当使用 PouchDB 的 get 方法时,如果传入的 ID 不存在,会返回一个 'missing' 错误。可以通过以下方法判断是否出现了 'missing' 错误:

  1. 检查返回的错误对象是否包含 'status' 属性,如果 'status' 属性为 404,则表示出现了 'missing' 错误。

  2. 检查返回的错误对象是否包含 'name' 属性,如果 'name' 属性为 'not_found',则表示出现了 'missing' 错误。

  3. 检查返回的错误对象是否包含 'message' 属性,如果 'message' 属性包含 'missing' 或 'not_found',则表示出现了 'missing' 错误。

例如:

db.get('nonexistent_id').catch(function (error) {
  if (error.status === 404 || error.name === 'not_found' || error.message.includes('missing')) {
    console.log('Missing error');
  }
});
PouchDB get() 方法:如何判断 'missing' 错误

原文地址: https://www.cveoy.top/t/topic/n4Rk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录