Added error handling for persist operation hook (#1531)

Unrelated CI failures. -.-
This commit is contained in:
Kevin Scroggins 2018-01-24 11:37:30 -05:00 committed by Kevin Delisle
parent 943fed851e
commit 07f0310d34
2 changed files with 12 additions and 0 deletions

View File

@ -3131,6 +3131,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
options: options,
};
Model.notifyObserversOf('persist', ctx, function(err) {
if (err) return cb(err);
invokeConnectorMethod(connector, 'replaceById', Model, [id, Model._forDB(context.data)],
options, replaceCallback);
});
@ -3327,6 +3328,7 @@ function(data, options, cb) {
options: options,
};
Model.notifyObserversOf('persist', ctx, function(err) {
if (err) return cb(err);
invokeConnectorMethod(connector, 'updateAttributes', Model,
[getIdValue(Model, inst), Model._forDB(context.data)],
options, updateAttributesCallback);

View File

@ -1489,6 +1489,16 @@ module.exports = function(dataSource, should, connectorCapabilities) {
});
});
it('emits error when `persist` hook fails', function(done) {
TestModel.observe('persist', nextWithError(expectedError));
TestModel.settings.updateOnLoad = true;
existingInstance.updateAttributes({name: 'test'}, function(err, instance) {
[err].should.eql([expectedError]);
done();
});
});
it('triggers `loaded` hook', function(done) {
TestModel.observe('loaded', ctxRecorder.recordAndNext());
existingInstance.updateAttributes({name: 'changed'}, function(err) {