diff --git a/Infrastructure/Persistence/Doctrine/Service/DuplicateEntryCommonErrorHandler.php b/Infrastructure/Persistence/Doctrine/Service/DuplicateEntryCommonErrorHandler.php index 6b566d3..261a7e5 100644 --- a/Infrastructure/Persistence/Doctrine/Service/DuplicateEntryCommonErrorHandler.php +++ b/Infrastructure/Persistence/Doctrine/Service/DuplicateEntryCommonErrorHandler.php @@ -37,8 +37,15 @@ public function handle(\Throwable $exception) $isDuplicatedError = $pdoException->getCode() === self::MYSQL_ERROR_DUPLICATE_ENTRY; if ($isDuplicatedError) { + preg_match( + '/Duplicate entry \'[_a-zA-Z0-9]+\' for key \'([_a-zA-Z0-9]+)\'/', + $exception->getMessage(), + $results + ); + $uniqueKey = $results[1] ?? 'unknown'; + throw new \DomainException( - 'Duplicated value found', + 'Duplicate value on key: ' . $uniqueKey, 0, $exception );