Lifecycle pre callbacks can be cancelled

In case that any Lifecycle pre callback returns Promise.reject it will be caught by Admin UI showing error banner.
It allows custom validations with Lifecycle callbacks as well
Admin UI will show saving process without it in case of error inside Lifecycle callback just writing error message in log.
This commit is contained in:
Andrey Hohutkin 2019-10-28 16:51:42 +02:00 committed by GitHub
parent 82b36df90c
commit c51c6b06c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,10 +129,9 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
if (_.isFunction(target[model.toLowerCase()][fn])) {
schema.pre(key, function(next) {
target[model.toLowerCase()]
return target[model.toLowerCase()]
[fn](this)
.then(next)
.catch(err => strapi.log.error(err));
.then(next);
});
}
});