Skip to content

Commit

Permalink
(#2028) - Switch to catch over .then(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf authored and daleharvey committed Apr 24, 2014
1 parent c1845be commit c09006b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function getCheckpoint(src, target, id) {
}
return 0;
});
}).then(null, function (err) {
}).catch(function (err) {
if (err.status !== 404) {
throw err;
}
Expand All @@ -85,7 +85,7 @@ function getCheckpoint(src, target, id) {

function writeCheckpoint(src, target, id, checkpoint, callback) {
function updateCheckpoint(db) {
return db.get(id).then(null, function (err) {
return db.get(id).catch(function (err) {
if (err.status === 404) {
return ({_id: id});
}
Expand Down Expand Up @@ -245,13 +245,11 @@ function replicate(repId, src, target, opts, returnValue) {
throw new Error('cancelled');
}
result.last_seq = last_seq = currentBatch.seq;
currentBatch.docs.forEach(function () {
result.docs_written++;
returnValue.emit('change', utils.clone(result));
});
result.docs_written += currentBatch.docs.length;
returnValue.emit('change', utils.clone(result));
currentBatch = undefined;
getChanges();
}).then(null, function (err) {
}).catch(function (err) {
writingCheckpoint = false;
abortReplication('writeCheckpoint completed with error', err);
throw err;
Expand Down Expand Up @@ -292,7 +290,7 @@ function replicate(repId, src, target, opts, returnValue) {
.then(writeDocs)
.then(finishBatch)
.then(startNextBatch)
.then(null, function (err) {
.catch(function (err) {
abortReplication('batch processing terminated with error', err);
});
}
Expand Down Expand Up @@ -419,7 +417,7 @@ function replicate(repId, src, target, opts, returnValue) {
src.changes(changesOpts)
.on('change', onChange)
.then(onChangesComplete)
.then(null, onChangesError);
.catch(onChangesError);
}
}

Expand All @@ -441,7 +439,7 @@ function replicate(repId, src, target, opts, returnValue) {
changesOpts.query_params = opts.query_params;
}
getChanges();
}).then(null, function (err) {
}).catch(function (err) {
abortReplication('getCheckpoint rejected with ', err);
});
}
Expand Down Expand Up @@ -472,7 +470,7 @@ function replicate(repId, src, target, opts, returnValue) {
}
last_seq = opts.since;
startChanges();
}).then(null, function (err) {
}).catch(function (err) {
writingCheckpoint = false;
abortReplication('writeCheckpoint completed with error', err);
throw err;
Expand Down

0 comments on commit c09006b

Please sign in to comment.