mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-04 12:29:43 +00:00
Introduce ConversionWithSameMimeTypeException
for improved error handling in document conversion.
- Added the `ConversionWithSameMimeTypeException` to handle cases where document conversion is requested for the same MIME type. - Updated `StoredObjectToPdfConverter` to throw the new exception when encountering such cases. - Enhanced error logging in `PostSendExternalMessageHandler` to capture these specific conversion errors.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Exception;
|
||||
|
||||
class ConversionWithSameMimeTypeException extends \RuntimeException
|
||||
{
|
||||
public function __construct(string $mimeType, ?\Throwable $previous = null)
|
||||
{
|
||||
parent::__construct("Conversion to same MIME type '{$mimeType}' is not allowed: already at the same MIME type", 0, $previous);
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectPointInTime;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectPointInTimeReasonEnum;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectVersion;
|
||||
use Chill\DocStoreBundle\Exception\ConversionWithSameMimeTypeException;
|
||||
use Chill\DocStoreBundle\Exception\StoredObjectManagerException;
|
||||
use Chill\WopiBundle\Service\WopiConverter;
|
||||
use Symfony\Component\Mime\MimeTypesInterface;
|
||||
@@ -41,9 +42,10 @@ class StoredObjectToPdfConverter
|
||||
*
|
||||
* @return array{0: StoredObjectPointInTime, 1: StoredObjectVersion, 2?: string} contains the point in time before conversion and the new version of the stored object. The converted content is included in the response if $includeConvertedContent is true
|
||||
*
|
||||
* @throws \UnexpectedValueException if the preferred mime type for the conversion is not found
|
||||
* @throws \RuntimeException if the conversion or storage of the new version fails
|
||||
* @throws \UnexpectedValueException if the preferred mime type for the conversion is not found
|
||||
* @throws \RuntimeException if the conversion or storage of the new version fails
|
||||
* @throws StoredObjectManagerException
|
||||
* @throws ConversionWithSameMimeTypeException if the document has already the same mime type79*
|
||||
*/
|
||||
public function addConvertedVersion(StoredObject $storedObject, string $lang, $convertTo = 'pdf', bool $includeConvertedContent = false): array
|
||||
{
|
||||
@@ -56,7 +58,7 @@ class StoredObjectToPdfConverter
|
||||
$currentVersion = $storedObject->getCurrentVersion();
|
||||
|
||||
if ($currentVersion->getType() === $newMimeType) {
|
||||
throw new \UnexpectedValueException('Already at the same mime type');
|
||||
throw new ConversionWithSameMimeTypeException($newMimeType);
|
||||
}
|
||||
|
||||
$content = $this->storedObjectManager->read($currentVersion);
|
||||
|
Reference in New Issue
Block a user