Last active
December 2, 2015 04:33
-
-
Save mickael-kerjean/a6fdda69372ace248b55 to your computer and use it in GitHub Desktop.
pouchdb_patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function writeDocs() { | |
// new line | |
changedDocs = []; | |
// end of new line | |
if (currentBatch.docs.length === 0) { | |
return; | |
} | |
var docs = currentBatch.docs; | |
return target.bulkDocs({docs: docs, new_edits: false}).then(function (res) { | |
if (returnValue.cancelled) { | |
completeReplication(); | |
throw new Error('cancelled'); | |
} | |
var errors = []; | |
var errorsById = {}; | |
res.forEach(function (res) { | |
if (res.error) { | |
result.doc_write_failures++; | |
errors.push(res); | |
errorsById[res.id] = res; | |
} | |
}); | |
allErrors = allErrors.concat(errors); | |
result.docs_written += currentBatch.docs.length - errors.length; | |
var non403s = errors.filter(function (error) { | |
return error.name !== 'unauthorized' && error.name !== 'forbidden'; | |
}); | |
// we don't need that here anymore | |
// changedDocs = []; | |
docs.forEach(function(doc) { | |
var error = errorsById[doc._id]; | |
if (error) { | |
returnValue.emit('denied', clone(error)); | |
} else { | |
changedDocs.push(doc); | |
} | |
}); | |
if (non403s.length > 0) { | |
var error = new Error('bulkDocs error'); | |
error.other_errors = errors; | |
abortReplication('target.bulkDocs failed to write docs', error); | |
throw new Error('bulkWrite partial failure'); | |
} | |
}, function (err) { | |
result.doc_write_failures += docs.length; | |
throw err; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment