diff --git a/.changes/unreleased/Fixed-20251003-130249.yaml b/.changes/unreleased/Fixed-20251003-130249.yaml new file mode 100644 index 000000000..b6db3cafc --- /dev/null +++ b/.changes/unreleased/Fixed-20251003-130249.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Add exception handling for conversion of attachment on sending external, when documens are already in pdf +time: 2025-10-03T13:02:49.524835257+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillDocStoreBundle/Exception/ConversionWithSameMimeTypeException.php b/src/Bundle/ChillDocStoreBundle/Exception/ConversionWithSameMimeTypeException.php new file mode 100644 index 000000000..06fb4a9ed --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Exception/ConversionWithSameMimeTypeException.php @@ -0,0 +1,20 @@ +getCurrentVersion(); if ($currentVersion->getType() === $newMimeType) { - throw new \UnexpectedValueException('Already at the same mime type'); + throw new ConversionWithSameMimeTypeException($newMimeType); } $content = $this->storedObjectManager->read($currentVersion); diff --git a/src/Bundle/ChillMainBundle/Workflow/Messenger/PostSendExternalMessageHandler.php b/src/Bundle/ChillMainBundle/Workflow/Messenger/PostSendExternalMessageHandler.php index 66888cce6..2e5f74808 100644 --- a/src/Bundle/ChillMainBundle/Workflow/Messenger/PostSendExternalMessageHandler.php +++ b/src/Bundle/ChillMainBundle/Workflow/Messenger/PostSendExternalMessageHandler.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Workflow\Messenger; +use Chill\DocStoreBundle\Exception\ConversionWithSameMimeTypeException; use Chill\DocStoreBundle\Exception\StoredObjectManagerException; use Chill\DocStoreBundle\Service\StoredObjectToPdfConverter; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; @@ -55,6 +56,8 @@ final readonly class PostSendExternalMessageHandler implements MessageHandlerInt $this->storedObjectToPdfConverter->addConvertedVersion($attachment->getProxyStoredObject(), $locale); } catch (StoredObjectManagerException $e) { $this->logger->error('Error converting attachment to PDF', ['backtrace' => $e->getTraceAsString(), 'attachment_id' => $attachment->getId()]); + } catch (ConversionWithSameMimeTypeException $e) { + $this->logger->error('Error converting attachment to PDF: already at the same MIME type', ['backtrace' => $e->getTraceAsString(), 'attachment_id' => $attachment->getId()]); } } @@ -65,6 +68,8 @@ final readonly class PostSendExternalMessageHandler implements MessageHandlerInt $this->storedObjectToPdfConverter->addConvertedVersion($storedObject, $locale); } catch (StoredObjectManagerException $e) { $this->logger->error('Error converting stored object to PDF', ['backtrace' => $e->getTraceAsString(), 'stored_object_id' => $storedObject->getId(), 'workflow_id' => $entityWorkflow->getId()]); + } catch (ConversionWithSameMimeTypeException $e) { + $this->logger->error('Error converting stored object to PDF: already at the same MIME type', ['backtrace' => $e->getTraceAsString(), 'stored_object_id' => $storedObject->getId(), 'workflow_id' => $entityWorkflow->getId()]); } } }