Skip to content

Commit

Permalink
log error
Browse files Browse the repository at this point in the history
  • Loading branch information
mdspeardevs committed Nov 13, 2024
1 parent b51e9a3 commit 9d55978
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/WebPushSender/WebPushSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BenTools\WebPushBundle\Model\Message\PushNotification;
use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerInterface;
use BenTools\WebPushBundle\Sender\PushMessageSender;
use Psr\Log\LoggerInterface;
use SpearDevs\SyliusPushNotificationsPlugin\Context\ChannelContextInterface;
use SpearDevs\SyliusPushNotificationsPlugin\Entity\PushNotificationTemplate\PushNotificationTemplate;
use SpearDevs\SyliusPushNotificationsPlugin\Factory\Interfaces\WebPushFactoryInterface;
Expand All @@ -20,6 +21,8 @@
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Translation\TranslatableMessage;
use Traversable;

final class WebPushSender implements WebPushSenderInterface
Expand All @@ -33,16 +36,19 @@ final class WebPushSender implements WebPushSenderInterface
public const GROUP_RECEIVER = 'group';

public function __construct(
private UserSubscriptionRepositoryInterface $userSubscriptionRepository,
private UserSubscriptionManagerInterface $userSubscriptionManager,
private PushMessageSender $sender,
private UserSubscriptionRepositoryInterface $userSubscriptionRepository,
private UserSubscriptionManagerInterface $userSubscriptionManager,
private PushMessageSender $sender,
private PushNotificationTemplateRepositoryInterface $pushNotificationTemplateRepository,
private PushNotificationConfigurationService $pushNotificationConfigurationService,
private WebPushHistoryCreatorInterface $webPushHistoryCreator,
private ChannelContextInterface $channelContext,
private WebPushFactoryInterface $webPushFactory,
private ParameterMapperInterface $orderParameterMapper,
) {
private PushNotificationConfigurationService $pushNotificationConfigurationService,
private WebPushHistoryCreatorInterface $webPushHistoryCreator,
private ChannelContextInterface $channelContext,
private WebPushFactoryInterface $webPushFactory,
private ParameterMapperInterface $orderParameterMapper,
private LoggerInterface $logger,
private SessionInterface $session,
)
{
}

public function sendWebPush(SendPushNotificationFormModel $sendPushNotificationFormModel): void
Expand Down Expand Up @@ -93,13 +99,21 @@ public function sendOrderWebPush(OrderInterface $order, string $pushNotification
$this->channelContext->setChannelCode($channel->getCode());

$webPush = $this->webPushFactory->create($this->orderParameterMapper, $order, $pushNotificationTemplate);

$this->sendToUser(
$webPush,
$channel,
$user->getEmail(),
);
try {
$this->sendToUser(
$webPush,
$channel,
$user->getEmail(),
);
} catch (\Exception $e) {
$this->session->getFlashBag()->add(
'error',
new TranslatableMessage('speardevs_sylius_push_notifications_plugin.ui.sent_error')
);
$this->logger->error('Problem while sending push notifications ' . $e->getMessage());
}
}

}

private function send(WebPushInterface $webPush, iterable $subscriptions): void
Expand Down

0 comments on commit 9d55978

Please sign in to comment.