()
| 9825 | } |
| 9826 | |
| 9827 | function writeDocs() { |
| 9828 | changedDocs = []; |
| 9829 | |
| 9830 | if (currentBatch.docs.length === 0) { |
| 9831 | return; |
| 9832 | } |
| 9833 | var docs = currentBatch.docs; |
| 9834 | var bulkOpts = {timeout: opts.timeout}; |
| 9835 | return target.bulkDocs({docs, new_edits: false}, bulkOpts).then(function (res$$1) { |
| 9836 | /* istanbul ignore if */ |
| 9837 | if (returnValue.cancelled) { |
| 9838 | completeReplication(); |
| 9839 | throw new Error('cancelled'); |
| 9840 | } |
| 9841 | |
| 9842 | // `res` doesn't include full documents (which live in `docs`), so we create a map of |
| 9843 | // (id -> error), and check for errors while iterating over `docs` |
| 9844 | var errorsById = Object.create(null); |
| 9845 | res$$1.forEach(function (res$$1) { |
| 9846 | if (res$$1.error) { |
| 9847 | errorsById[res$$1.id] = res$$1; |
| 9848 | } |
| 9849 | }); |
| 9850 | |
| 9851 | var errorsNo = Object.keys(errorsById).length; |
| 9852 | result.doc_write_failures += errorsNo; |
| 9853 | result.docs_written += docs.length - errorsNo; |
| 9854 | |
| 9855 | docs.forEach(function (doc) { |
| 9856 | var error = errorsById[doc._id]; |
| 9857 | if (error) { |
| 9858 | result.errors.push(error); |
| 9859 | // Normalize error name. i.e. 'Unauthorized' -> 'unauthorized' (eg Sync Gateway) |
| 9860 | var errorName = (error.name || '').toLowerCase(); |
| 9861 | if (errorName === 'unauthorized' || errorName === 'forbidden') { |
| 9862 | returnValue.emit('denied', clone(error)); |
| 9863 | } else { |
| 9864 | throw error; |
| 9865 | } |
| 9866 | } else { |
| 9867 | changedDocs.push(doc); |
| 9868 | } |
| 9869 | }); |
| 9870 | |
| 9871 | }, function (err) { |
| 9872 | result.doc_write_failures += docs.length; |
| 9873 | throw err; |
| 9874 | }); |
| 9875 | } |
| 9876 | |
| 9877 | function finishBatch() { |
| 9878 | if (currentBatch.error) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…