Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use CoreShop\Component\Pimcore\DataObject\NoteServiceInterface;
use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Resource\Factory\PimcoreFactoryInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -187,8 +188,18 @@ public function renderAction(Request $request): Response
'Content-Disposition' => 'inline; filename="invoice-' . $invoice->getId() . '.pdf"',
];
} catch (\Exception $e) {
$responseData = '<strong>' . $e->getMessage() . '</strong><br>trace: ' . $e->getTraceAsString();
$this->container->get(LoggerInterface::class)->error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove log and don't overexpose response

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the logging and simplified the error response to just return a generic message with HTTP 500 status. Fixed in de3345e.

'Failed to render invoice PDF',
[
'invoiceId' => $invoice->getId(),
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
],
);
$responseData = 'An error occurred while rendering the invoice. Please try again later.';
$header = ['Content-Type' => 'text/html'];

return new Response($responseData, 500, $header);
}

return new Response($responseData, 200, $header);
Expand Down Expand Up @@ -244,6 +255,7 @@ public static function getSubscribedServices(): array
new SubscribedService('coreshop.order.transformer.order_to_invoice', OrderDocumentTransformerInterface::class, attributes: new Autowire('@CoreShop\Component\Order\Transformer\OrderToInvoiceTransformer')),
new SubscribedService('coreshop.repository.order_invoice', OrderInvoiceRepositoryInterface::class, attributes: new Autowire(service:'coreshop.repository.order_invoice')),
new SubscribedService(StateMachineManagerInterface::class, StateMachineManagerInterface::class),
new SubscribedService(LoggerInterface::class, LoggerInterface::class),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use CoreShop\Component\Order\Transformer\OrderToShipmentTransformer;
use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -183,8 +184,18 @@ public function renderAction(Request $request): Response
'Content-Disposition' => 'inline; filename="shipment-' . $shipment->getId() . '.pdf"',
];
} catch (\Exception $e) {
$responseData = '<strong>' . $e->getMessage() . '</strong><br>trace: ' . $e->getTraceAsString();
$this->container->get(LoggerInterface::class)->error(
'Failed to render shipment PDF',
[
'shipmentId' => $shipment->getId(),
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
],
);
$responseData = 'An error occurred while rendering the shipment. Please try again later.';
$header = ['Content-Type' => 'text/html'];

return new Response($responseData, 500, $header);
}

return new Response($responseData, 200, $header);
Expand Down Expand Up @@ -240,6 +251,7 @@ public static function getSubscribedServices(): array
new SubscribedService('event_dispatcher', EventDispatcherInterface::class),
new SubscribedService(OrderToShipmentTransformer::class, OrderToShipmentTransformer::class),
new SubscribedService(ErrorSerializer::class, ErrorSerializer::class),
new SubscribedService(LoggerInterface::class, LoggerInterface::class),
]);
}
}