How to use the pouchdb-errors.generateErrorFromResponse 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-ajax / src / ajaxCore.js View on Github external
// CouchDB doesn't always return the right content-type for JSON data, so
    // we check for ^{ and }$ (ignoring leading/trailing whitespace)
    if (!options.binary && (options.json || !options.processData) &&
        typeof data !== 'object' &&
        (/json/.test(content_type) ||
         (/^[\s]*\{/.test(data) && /\}[\s]*$/.test(data)))) {
      try {
        data = JSON.parse(data.toString());
      } catch (e) {}
    }

    if (response.statusCode >= 200 && response.statusCode < 300) {
      onSuccess(data, response, callback);
    } else {
      error = generateErrorFromResponse(data);
      error.status = response.statusCode;
      callback(error);
    }
  });
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-ajax / src / ajaxCore.js View on Github external
return request(options, function (err, response, body) {

    if (err) {
      return callback(generateErrorFromResponse(err));
    }

    var error;
    var content_type = response.headers && response.headers['content-type'];
    var data = body || defaultBody();

    // CouchDB doesn't always return the right content-type for JSON data, so
    // we check for ^{ and }$ (ignoring leading/trailing whitespace)
    if (!options.binary && (options.json || !options.processData) &&
        typeof data !== 'object' &&
        (/json/.test(content_type) ||
         (/^[\s]*\{/.test(data) && /\}[\s]*$/.test(data)))) {
      try {
        data = JSON.parse(data.toString());
      } catch (e) {}
    }
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / http / index.js View on Github external
}).then(function (json) {
    if (!ok) {
      json.status = status;
      var err = generateErrorFromResponse(json);
      callback(err);
    } else {
      callback(null, json);
    }
  }).catch(callback);
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-http / src / index.js View on Github external
}).then(function (json) {
      result.data = json;
      if (!result.ok) {
        result.data.status = result.status;
        var err = generateErrorFromResponse(result.data);
        if (callback) {
          return callback(err);
        } else {
          throw err;
        }
      }

      if (Array.isArray(result.data)) {
        result.data = result.data.map(function (v) {
          if (v.error || v.missing) {
            return generateErrorFromResponse(v);
          } else {
            return v;
          }
        });
      }
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-http / src / index.js View on Github external
result.data = result.data.map(function (v) {
          if (v.error || v.missing) {
            return generateErrorFromResponse(v);
          } else {
            return v;
          }
        });
      }
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / bulk_docs.js View on Github external
processAllAttachments(newDoc.data)
        .then(attachments => {
          const change = oldDoc ? getUpdate() : getInsert()
          if (change.error) return reject(change.error)
          if (attachments) change.attachments = attachments
          resolve(change)
        })
        .catch(reject)
    })
  }

  let newDocs
  try {
    newDocs = req.docs.map(mapRequestDoc)
  } catch (error) {
    return callback(generateErrorFromResponse(error))
  }

  const docIds = newDocs.map(doc => forDocument(doc.id))
  db.storage.multiGet(docIds, (error, oldDocs) => {
    if (error) return callback(generateErrorFromResponse(error))

    const oldDocsObj = oldDocs.reduce((result, doc) => {
      if (doc && doc.id) result[doc.id] = doc
      return result
    }, {})

    const promises = newDocs.map(newDoc => {
      let oldDoc = oldDocsObj[newDoc.id]
      oldDoc = typeof oldDoc === 'function' ? undefined : oldDoc

      return getChange(oldDoc, newDoc)
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / all_docs.js View on Github external
(error, docs) => {
      if (error) return callback(generateErrorFromResponse(error))

      let rows = docs.map(docToRow)

      callback(null, {
        total_rows: db.meta.doc_count,
        offset: skip,
        rows
      })
    }
  )
github pouchdb / pouchdb / packages / node_modules / pouchdb-ajax / src / ajaxCore.js View on Github external
obj = obj.map(function (v) {
        if (v.error || v.missing) {
          return generateErrorFromResponse(v);
        } else {
          return v;
        }
      });
    }
github pouchdb / pouchdb / packages / node_modules / pouchdb-abstract-mapreduce / src / index.js View on Github external
}).then(function (result) {
      if (!ok) {
        result.status = status;
        throw generateErrorFromResponse(result);
      }
      return result;
    }).then(postprocessAttachments(opts));
  }