Replace ValidationError by ApplicationError in services & lifecycles
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { ValidationError, NotFoundError } = require("@strapi/utils").errors
|
||||
const { ApplicationError, NotFoundError } = require("@strapi/utils").errors
|
||||
|
||||
const jwennUserEpiId = async userId => {
|
||||
if (!userId) {
|
||||
@@ -28,15 +28,15 @@ const jwennParoleEpiId = async paroleId => {
|
||||
|
||||
const validateCommentaire = data => {
|
||||
if (!data.contenu && !data.datePublication) {
|
||||
throw new ValidationError('Mauvaise requête, contenu et datePublication sont obligatoires')
|
||||
throw new ApplicationError('Mauvaise requête, contenu et datePublication sont obligatoires')
|
||||
}
|
||||
|
||||
if (!data.contenu || data.contenu.trim().length === 0) {
|
||||
throw new ValidationError('Champ obligatoire. Veuillez renseigner le contenu du commentaire.')
|
||||
throw new ApplicationError('Champ obligatoire. Veuillez renseigner le contenu du commentaire.')
|
||||
}
|
||||
|
||||
if (data.contenu.trim().length > 500) {
|
||||
throw new ValidationError('Le commentaire doit contenir 500 caractères maximum.')
|
||||
throw new ApplicationError('Le commentaire doit contenir 500 caractères maximum.')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
const { ValidationError, NotFoundError, UnauthorizedError } = require("@strapi/utils").errors
|
||||
const { ApplicationError, NotFoundError, UnauthorizedError } = require("@strapi/utils").errors
|
||||
|
||||
module.exports = createCoreController('api::commentaire.commentaire', ({strapi}) => ({
|
||||
async create(ctx) {
|
||||
@@ -28,7 +28,7 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
|
||||
}
|
||||
|
||||
if (user.id !== data.user.id || user.username !== data.user.username || user.email !== data.user.email) {
|
||||
throw new ValidationError('Informations non valides.')
|
||||
throw new ApplicationError('Informations non valides.')
|
||||
}
|
||||
|
||||
data.user = user.id
|
||||
|
||||
Reference in New Issue
Block a user