Skip to content

Commit 59e9381

Browse files
committed
remove vestigial :error post hook calls
1 parent 0f6b4aa commit 59e9381

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Diff for: lib/plugins/saveSubdocs.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ module.exports = function saveSubdocs(schema) {
3232
_this.$__.saveOptions.__subdocs = null;
3333
}
3434
if (error) {
35-
return _this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
36-
next(error);
37-
});
35+
return next(error);
3836
}
3937
next();
4038
});
@@ -67,7 +65,6 @@ module.exports = function saveSubdocs(schema) {
6765
return;
6866
}
6967

70-
const _this = this;
7168
const subdocs = this.$getAllSubdocs({ useCache: true });
7269

7370
if (!subdocs.length) {
@@ -86,17 +83,6 @@ module.exports = function saveSubdocs(schema) {
8683
}));
8784
}
8885

89-
try {
90-
await Promise.all(promises);
91-
} catch (error) {
92-
await new Promise((resolve, reject) => {
93-
this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
94-
if (error) {
95-
return reject(error);
96-
}
97-
resolve();
98-
});
99-
});
100-
}
86+
await Promise.all(promises);
10187
}, null, unshift);
10288
};

Diff for: test/model.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -2154,17 +2154,23 @@ describe('Model', function() {
21542154
next();
21552155
});
21562156

2157+
let schemaPostSaveCalls = 0;
21572158
const schema = new Schema({ name: String, child: [childSchema] });
21582159
schema.pre('save', function(next) {
21592160
this.name = 'parent';
21602161
next();
21612162
});
2163+
schema.post('save', function testSchemaPostSave(err, res, next) {
2164+
++schemaPostSaveCalls;
2165+
next(err);
2166+
});
21622167

21632168
const S = db.model('Test', schema);
21642169
const s = new S({ name: 'a', child: [{ name: 'b', grand: [{ name: 'c' }] }] });
21652170

21662171
const err = await s.save().then(() => null, err => err);
21672172
assert.equal(err.message, 'Error 101');
2173+
assert.equal(schemaPostSaveCalls, 1);
21682174
});
21692175

21702176
describe('init', function() {

0 commit comments

Comments
 (0)