Replace ValidationError by ApplicationError in services & lifecycles

This commit is contained in:
2023-04-02 12:25:52 +04:00
parent a65b3f04e8
commit d61ef75869
5 changed files with 18 additions and 16 deletions
@@ -2,7 +2,9 @@
const slugify = require('slugify')
const axios = require('axios')
const { ValidationError } = require("@strapi/utils").errors
const utils = require('@strapi/utils')
const { ApplicationError } = utils.errors
const TELEGRAM_API_URL = 'https://api.telegram.org'
const TELEGRAM_CHAN_ID = process.env.TELEGRAM_CHAN_ID || null
@@ -28,7 +30,7 @@ const isSlugExists = async existingSlug => {
const jwennAwtisEpiId = async artistesIds => {
console.log('artistesIds', artistesIds)
if (artistesIds.length === 0) {
throw new ValidationError('Champ obligatoire. Veuillez choisir au moins un artiste.');
throw new ApplicationError('Champ obligatoire. Veuillez choisir au moins un artiste.');
}
const artistes = await strapi.db.query('api::artiste.artiste').findMany({
@@ -53,7 +55,7 @@ const jwennUserEpiId = async userId => {
})
if (!user) {
throw new ValidationError('Utilisateur introuvable.')
throw new ApplicationError('Utilisateur introuvable.')
}
return user
@@ -128,7 +130,7 @@ module.exports = {
const getSlugExistance = await isSlugExists(data.slug)
if (getSlugExistance) {
throw new ValidationError('Un morceau du même artiste existe déjà.')
throw new ApplicationError('Un morceau du même artiste existe déjà.')
}
},
beforeUpdate: async event => {
+4 -4
View File
@@ -4,7 +4,7 @@ const axios = require('axios')
const Diff = require('diff')
const { createCoreService } = require('@strapi/strapi').factories;
const { ValidationError } = require("@strapi/utils").errors
const { ApplicationError } = require("@strapi/utils").errors
class Translator {
constructor() {
@@ -56,15 +56,15 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
},
validateParoles(titre, transcription) {
if (!titre || titre.trim().length === 0) {
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
throw new ApplicationError('Champ obligatoire. Veuillez choisir un titre.');
}
if (!transcription || transcription.trim().length === 0) {
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
throw new ApplicationError('Champ obligatoire. Veuillez renseigner la transcription.')
}
if (transcription.trim().length < 10) {
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
throw new ApplicationError('La transcription doit contenir au moins 10 caractères.')
}
},
parolesDiff(titre = '', oldString, newString) {