mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Fix #2211: Content-Manager: save not handling beforeSave hook throw error
This commit is contained in:
parent
afbc90ce9c
commit
ed924b057a
@ -174,7 +174,10 @@ module.exports = function (strapi) {
|
||||
_.forEach(postLifecycle, (fn, key) => {
|
||||
if (_.isFunction(target[model.toLowerCase()][fn])) {
|
||||
collection.schema.post(key, function (doc, next) {
|
||||
target[model.toLowerCase()][fn](this, doc).then(next).catch(err => strapi.log.error(err));
|
||||
target[model.toLowerCase()][fn](this, doc).then(next).catch(err => {
|
||||
strapi.log.error(err);
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -106,11 +106,13 @@ module.exports = {
|
||||
|
||||
const request = await this.create(values)
|
||||
.catch((err) => {
|
||||
const message = err.message.split('index:');
|
||||
const field = _.words(_.last(message).split('_')[0]);
|
||||
const error = { message: `This ${field} is already taken`, field };
|
||||
|
||||
throw error;
|
||||
if (err.message)
|
||||
{
|
||||
const message = err.message.split('index:');
|
||||
const field = _.words(_.last(message).split('_')[0]);
|
||||
err = { message: `This ${field} is already taken`, field };
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Transform to JSON object.
|
||||
|
Loading…
x
Reference in New Issue
Block a user