From 14f0e2ffb88f2781ba490dcda2de8bf6cd9815ac Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 7 Oct 2024 21:29:32 +0200 Subject: [PATCH] fix(notification): Throw new exceptions to stop debug logs Signed-off-by: Joas Schilling --- lib/Activity/Provider.php | 6 +++--- lib/Notification/Notifier.php | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php index 04393647e..073d063dc 100644 --- a/lib/Activity/Provider.php +++ b/lib/Activity/Provider.php @@ -9,13 +9,13 @@ namespace OCA\Circles\Activity; -use InvalidArgumentException; use OCA\Circles\AppInfo\Application; use OCA\Circles\Exceptions\FakeException; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCA\Circles\Tools\Traits\TDeserialize; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\Activity\IProvider; @@ -61,11 +61,11 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): */ private function initActivityParser(IEvent $event, array $params): void { if ($event->getApp() !== Application::APP_ID) { - throw new InvalidArgumentException(); + throw new UnknownActivityException(); } if (!key_exists('circle', $params)) { - throw new InvalidArgumentException(); + throw new UnknownActivityException(); } } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 1c14045ce..fe12473e8 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -12,7 +12,6 @@ namespace OCA\Circles\Notification; use Exception; -use InvalidArgumentException; use OCA\Circles\AppInfo\Application; use OCA\Circles\Exceptions\FederatedUserException; use OCA\Circles\Exceptions\FederatedUserNotFoundException; @@ -30,8 +29,10 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\L10N\IFactory; +use OCP\Notification\AlreadyProcessedException; use OCP\Notification\INotification; use OCP\Notification\INotifier; +use OCP\Notification\UnknownNotificationException; /** * Class Notifier @@ -114,11 +115,12 @@ public function getName(): string { * @param string $languageCode The code of the language that should be used to prepare the notification * * @return INotification - * @throws InvalidArgumentException + * @throws UnknownNotificationException + * @throws AlreadyProcessedException */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== Application::APP_ID) { - throw new InvalidArgumentException(); + throw new UnknownNotificationException(); } $iconPath = $this->urlGenerator->imagePath(Application::APP_ID, 'circles.svg'); @@ -127,8 +129,10 @@ public function prepare(INotification $notification, string $languageCode): INot if ($notification->getObjectType() === 'member') { try { $this->prepareMemberNotification($notification); + } catch (UnknownNotificationException $e) { + throw $e; } catch (Exception $e) { - // TODO: delete notification + throw new AlreadyProcessedException(); } } @@ -148,6 +152,7 @@ public function prepare(INotification $notification, string $languageCode): INot * @throws FederatedUserNotFoundException * @throws InvalidIdException * @throws SingleCircleNotFoundException + * @throws UnknownNotificationException */ private function prepareMemberNotification(INotification $notification) { $this->federatedUserService->initCurrentUser($notification->getUser()); @@ -193,7 +198,7 @@ private function prepareMemberNotification(INotification $notification) { break; default: - throw new InvalidArgumentException(); + throw new UnknownNotificationException(); } $notification->setParsedSubject($subject);