How to use the pouchdb-errors.createError function in pouchdb-errors

To help you get started, we’ve selected a few pouchdb-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pouchdb / pouchdb / packages / node_modules / pouchdb-core / src / adapter.js View on Github external
}

  var attachmentError;
  req.docs.forEach(function (doc) {
    if (doc._attachments) {
      Object.keys(doc._attachments).forEach(function (name) {
        attachmentError = attachmentError || attachmentNameError(name);
        if (!doc._attachments[name].content_type) {
          guardedConsole('warn', 'Attachment', name, 'on document', doc._id, 'is missing content_type');
        }
      });
    }
  });

  if (attachmentError) {
    return callback(createError(BAD_REQUEST, attachmentError));
  }

  if (!('new_edits' in opts)) {
    if ('new_edits' in req) {
      opts.new_edits = req.new_edits;
    } else {
      opts.new_edits = true;
    }
  }

  var adapter = this;
  if (!opts.new_edits && !isRemote(adapter)) {
    // ensure revisions of the same doc are sorted, so that
    // the local adapter processes them correctly (#2935)
    req.docs.sort(compareByIdThenRev);
  }
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / src / index.js View on Github external
stores.docStore.get(id, function (err, metadata) {
      if (err || !metadata) {
        return callback(createError(MISSING_DOC, 'missing'))
      }

      var rev = getWinningRev(metadata)
      var deleted = getIsDeleted(metadata, rev)
      if (deleted && !opts.rev) {
        return callback(createError(MISSING_DOC, 'deleted'))
      }

      rev = opts.rev ? opts.rev : rev

      var seq = metadata.rev_map[rev]

      stores.bySeqStore.get(formatSeq(seq), function (err, doc) {
        if (err) {
          return callback(createError(MISSING_DOC, 'error'))
        }
        if (!doc) {
          return callback(createError(MISSING_DOC))
        }
        /* istanbul ignore if */
        if ('_id' in doc && doc._id !== metadata.id) {
          // this failing implies something very wrong
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-utils / src / processDocs.js View on Github external
function insertDoc(docInfo, resultsIdx, callback) {
    // Cant insert new deleted documents
    var winningRev = calculateWinningRev(docInfo.metadata);
    var deleted = isDeleted(docInfo.metadata, winningRev);
    if ('was_delete' in opts && deleted) {
      results[resultsIdx] = createError(MISSING_DOC, 'deleted');
      return callback();
    }

    // 4712 - detect whether a new document was inserted with a _rev
    var inConflict = newEdits && rootIsMissing(docInfo);

    if (inConflict) {
      var err = createError(REV_CONFLICT);
      results[resultsIdx] = err;
      return callback();
    }

    var delta = deleted ? 0 : 1;

    writeDoc(docInfo, winningRev, deleted, deleted, false,
      delta, resultsIdx, callback);
  }
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / src / index.js View on Github external
txn.get(stores.localStore, doc._id, function (err, resp) {
      if (err) {
        /* istanbul ignore if */
        if (err.name !== 'NotFoundError') {
          return callback(err);
        } else {
          return callback(createError(MISSING_DOC));
        }
      }
      if (resp._rev !== doc._rev) {
        return callback(createError(REV_CONFLICT));
      }
      txn.batch([{
        prefix: stores.localStore,
        type: 'del',
        key: doc._id
      }]);
      var ret = {ok: true, id: doc._id, rev: '0-0'};
      if (opts.ctx) {
        // don't execute immediately
        return callback(null, ret);
      }
      txn.execute(db, function (err) {
        /* istanbul ignore if */
        if (err) {
          return callback(err);
        }
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-utils / src / parseDoc.js View on Github external
function parseRevisionInfo(rev) {
  if (!/^\d+-/.test(rev)) {
    return createError(INVALID_REV);
  }
  var idx = rev.indexOf('-');
  var left = rev.substring(0, idx);
  var right = rev.substring(idx + 1);
  return {
    prefix: parseInt(left, 10),
    id: right
  };
}
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / get_revision_tree.js View on Github external
db.storage.get(forDocument(id), (error, doc) => {
    if (error) {
      return callback(
        createError(MISSING_DOC, error.message || 'missing-read-error')
      )
    }

    if (!doc) {
      return callback(createError(MISSING_DOC, 'missing-rev-tree'))
    }

    callback(null, doc.rev_tree)
  })
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-leveldb-core / src / index.js View on Github external
stores.docStore.get(docId, function (err, metadata) {
      if (err) {
        callback(createError(MISSING_DOC));
      } else {
        callback(null, metadata.rev_tree);
      }
    });
  };
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage-pure / src / get_revision_tree.js View on Github external
db.storage.get(keys.forDocument(id), (error, doc) => {
    if (error) {
      return callback(createError(
        MISSING_DOC, error.message || 'missing-read-error'))
    }

    if (!doc) {
      return callback(createError(MISSING_DOC, 'missing'))
    }

    callback(null, doc.rev_tree)
  })
}
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / get.js View on Github external
db.storage.get(forDocument(id), (error, meta) => {
    if (error) {
      return callback(
        createError(MISSING_DOC, error.message || 'missing-read-error')
      )
    }
    if (meta === null) {
      return callback(createError(MISSING_DOC, 'missing-no-meta-found'))
    }

    const rev = opts.rev || winningRev(meta)
    if (!meta || (meta.deleted && !opts.rev) || !(rev in meta.rev_map)) {
      return callback(createError(MISSING_DOC, 'missing-rev-check'))
    }

    db.storage.get(forSequence(meta.rev_map[rev]), (error, doc) => {
      if (error) {
        return callback(
          createError(MISSING_DOC, error.message || 'missing-read-error')
        )
      }

      return callback(null, { doc, metadata: meta })
    })
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / bulk_docs.js View on Github external
db.storage.get(attachmentKey, (error, data) => {
            if (error) return reject(createError(MISSING_STUB, error.message))
            if (!data)
              return reject(
                createError(MISSING_STUB, 'can not find attachment')
              )
            return resolve({
              attachment,
              dbAttachment: [attachmentKey, data]
            })
          })
        })