Skip to content

Commit

Permalink
fix(notification): Throw new exceptions to stop debug logs
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 7, 2024
1 parent bc902bc commit 14f0e2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand Down
15 changes: 10 additions & 5 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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');
Expand All @@ -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();
}
}

Expand All @@ -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());
Expand Down Expand Up @@ -193,7 +198,7 @@ private function prepareMemberNotification(INotification $notification) {
break;

default:
throw new InvalidArgumentException();
throw new UnknownNotificationException();
}

$notification->setParsedSubject($subject);
Expand Down

0 comments on commit 14f0e2f

Please sign in to comment.