fix(composant) : scaffold skeleton slots on creation + explicit unique constraint errors
- Add ComposantProcessor: initializes piece/product/subcomponent slots from ModelType skeleton requirements when a composant is created - UniqueConstraintSubscriber: priority 256, French error messages, constraint name detection for specific feedback - Migration: scaffold missing slots for existing composants in prod Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ final class UniqueConstraintSubscriber implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::EXCEPTION => 'onKernelException',
|
||||
KernelEvents::EXCEPTION => ['onKernelException', 256],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,10 +28,17 @@ final class UniqueConstraintSubscriber implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$constraint = $this->detectConstraintName($exception);
|
||||
$error = match ($constraint) {
|
||||
'unique_category_name' => 'Un élément avec ce nom existe déjà dans cette catégorie.',
|
||||
default => 'Un élément avec cette valeur existe déjà.',
|
||||
};
|
||||
|
||||
$event->setResponse(new JsonResponse(
|
||||
[
|
||||
'success' => false,
|
||||
'error' => 'nom duplique',
|
||||
'success' => false,
|
||||
'error' => $error,
|
||||
'constraint' => $constraint,
|
||||
],
|
||||
JsonResponse::HTTP_CONFLICT
|
||||
));
|
||||
@@ -47,4 +54,15 @@ final class UniqueConstraintSubscriber implements EventSubscriberInterface
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function detectConstraintName(UniqueConstraintViolationException $exception): ?string
|
||||
{
|
||||
$message = $exception->getMessage();
|
||||
|
||||
if (preg_match('/constraint\s+"([^"]+)"/', $message, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user