mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +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) => {
|
_.forEach(postLifecycle, (fn, key) => {
|
||||||
if (_.isFunction(target[model.toLowerCase()][fn])) {
|
if (_.isFunction(target[model.toLowerCase()][fn])) {
|
||||||
collection.schema.post(key, function (doc, next) {
|
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)
|
const request = await this.create(values)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const message = err.message.split('index:');
|
if (err.message)
|
||||||
const field = _.words(_.last(message).split('_')[0]);
|
{
|
||||||
const error = { message: `This ${field} is already taken`, field };
|
const message = err.message.split('index:');
|
||||||
|
const field = _.words(_.last(message).split('_')[0]);
|
||||||
throw error;
|
err = { message: `This ${field} is already taken`, field };
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Transform to JSON object.
|
// Transform to JSON object.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user