Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(notification): Throw new exceptions to stop debug logs #1712

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading