Replace ValidationError by ctx errors in controllers
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
const { ValidationError } = require("@strapi/utils").errors
|
||||
const slugify = require('slugify')
|
||||
|
||||
const getSlug = text => {
|
||||
@@ -34,7 +33,7 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
|
||||
}
|
||||
|
||||
if (user.id !== data.user.id || user.username !== data.user.username || user.email !== data.user.email) {
|
||||
throw new ValidationError('Informations non valides.')
|
||||
ctx.badRequest('Informations non valides.')
|
||||
}
|
||||
|
||||
const artiste = await strapi.db.query('api::artiste.artiste').findOne({
|
||||
|
||||
@@ -34,27 +34,27 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
|
||||
].services.jwt.getToken(ctx)
|
||||
|
||||
if (id !== data.user.id) {
|
||||
throw new UnauthorizedError('Opération non autorisée')
|
||||
ctx.unauthorized('Opération non autorisée')
|
||||
}
|
||||
} catch (err) {
|
||||
throw new UnauthorizedError(ctx, err, 'Opération non autorisée')
|
||||
ctx.unauthorized(ctx, err, 'Opération non autorisée')
|
||||
}
|
||||
}
|
||||
|
||||
const user = await strapi.entityService.findOne('plugin::users-permissions.user', body.data.user.id)
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundError('Utilisateur introuvable.')
|
||||
ctx.notFound('Utilisateur introuvable.')
|
||||
}
|
||||
|
||||
if (user.id !== data.user.id || user.username !== data.user.username || user.email !== data.user.email) {
|
||||
throw new ValidationError('Informations non valides.')
|
||||
ctx.badRequest('Informations non valides.')
|
||||
}
|
||||
|
||||
const artiste = await strapi.entityService.findOne('api::artiste.artiste', data.artistes[0])
|
||||
|
||||
if (!artiste) {
|
||||
throw new NotFoundError('Artiste introuvable.')
|
||||
ctx.notFound('Artiste introuvable.')
|
||||
}
|
||||
|
||||
const currentUserParole = await strapi.entityService.findMany('api::parole.parole', {
|
||||
|
||||
Reference in New Issue
Block a user