diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index ea188f9094d..5676eb085e8 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -187,7 +187,7 @@ protected function generateCallActivity(Room $room, bool $endForEveryone = false try { $event->setAffectedUser($userId); $this->activityManager->publish($event); - } catch (\BadMethodCallException|\InvalidArgumentException $e) { + } catch (\Throwable $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); } } @@ -219,7 +219,7 @@ protected function generateInvitationActivity(Room $room, array $attendees): voi 'user' => $actor->getUID(), 'room' => $room->getId(), ]); - } catch (\InvalidArgumentException $e) { + } catch (\Throwable $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); return; } @@ -254,7 +254,7 @@ protected function generateInvitationActivity(Room $room, array $attendees): voi ]) ->setAffectedUser($attendee->getActorId()); $this->activityManager->publish($event); - } catch (\BadMethodCallException|\InvalidArgumentException $e) { + } catch (\Throwable $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); } } diff --git a/lib/Activity/Provider/Base.php b/lib/Activity/Provider/Base.php index 9a2817776f1..1c292a5572a 100644 --- a/lib/Activity/Provider/Base.php +++ b/lib/Activity/Provider/Base.php @@ -27,6 +27,7 @@ use OCA\Talk\Manager; use OCA\Talk\Room; use OCA\Talk\Service\AvatarService; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\Activity\IProvider; @@ -52,17 +53,17 @@ public function __construct( /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException */ public function preParse(IEvent $event): IEvent { if ($event->getApp() !== 'spreed') { - throw new \InvalidArgumentException('Wrong app'); + throw new UnknownActivityException('app'); } $uid = $event->getAffectedUser(); $user = $this->userManager->get($uid); if (!$user instanceof IUser || $this->config->isDisabledForUser($user)) { - throw new \InvalidArgumentException('User can not user Talk'); + throw new UnknownActivityException('User can not use Talk'); } if ($this->activityManager->getRequirePNG()) { @@ -78,7 +79,6 @@ public function preParse(IEvent $event): IEvent { * @param IEvent $event * @param string $subject * @param array $parameters - * @throws \InvalidArgumentException */ protected function setSubjects(IEvent $event, string $subject, array $parameters): void { $placeholders = $replacements = []; diff --git a/lib/Activity/Provider/Call.php b/lib/Activity/Provider/Call.php index 59e5006f7a7..da2c0b7cd0d 100644 --- a/lib/Activity/Provider/Call.php +++ b/lib/Activity/Provider/Call.php @@ -23,6 +23,7 @@ namespace OCA\Talk\Activity\Provider; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\IL10N; @@ -32,7 +33,7 @@ class Call extends Base { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { @@ -54,7 +55,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): // $result['params']['call'] = $roomParameter; $this->setSubjects($event, $result['subject'], $result['params']); } else { - throw new \InvalidArgumentException('Wrong subject'); + throw new UnknownActivityException('subject'); } return $event; @@ -80,7 +81,7 @@ protected function parseCall(IEvent $event, IL10N $l): array { $currentUser = array_search($this->activityManager->getCurrentUserId(), $parameters['users'], true); if ($currentUser === false) { - throw new \InvalidArgumentException('Unknown case'); + throw new UnknownActivityException('Unknown case'); } unset($parameters['users'][$currentUser]); sort($parameters['users']); diff --git a/lib/Activity/Provider/Invitation.php b/lib/Activity/Provider/Invitation.php index bd75646cade..7373d3b5777 100644 --- a/lib/Activity/Provider/Invitation.php +++ b/lib/Activity/Provider/Invitation.php @@ -24,6 +24,7 @@ namespace OCA\Talk\Activity\Provider; use OCA\Talk\Exceptions\RoomNotFoundException; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; class Invitation extends Base { @@ -32,7 +33,7 @@ class Invitation extends Base { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { @@ -54,7 +55,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): 'call' => $roomParameter, ]); } else { - throw new \InvalidArgumentException('Wrong subject'); + throw new UnknownActivityException('subject'); } return $event; diff --git a/tests/php/Activity/Provider/BaseTest.php b/tests/php/Activity/Provider/BaseTest.php index 71b9ccd70d0..cbe66ccf469 100644 --- a/tests/php/Activity/Provider/BaseTest.php +++ b/tests/php/Activity/Provider/BaseTest.php @@ -28,6 +28,7 @@ use OCA\Talk\Manager; use OCA\Talk\Room; use OCA\Talk\Service\AvatarService; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\IURLGenerator; @@ -65,9 +66,8 @@ public function setUp(): void { /** * @param string[] $methods - * @return Base|MockObject */ - protected function getProvider(array $methods = []) { + protected function getProvider(array $methods = []): Base&MockObject { $methods[] = 'parse'; return $this->getMockBuilder(Base::class) ->setConstructorArgs([ @@ -106,7 +106,7 @@ public function testPreParse(string $appId, bool $hasUser, bool $disabledForUser ->willReturn($appId); if ($willThrowException) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(UnknownActivityException::class); } $event->expects($this->exactly($willThrowException ? 0 : 1)) ->method('setIcon') @@ -137,7 +137,7 @@ public function testPreParseThrows(): void { ->method('getApp') ->willReturn('activity'); $provider = $this->getProvider(); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(UnknownActivityException::class); static::invokePrivate($provider, 'preParse', [$event]); } diff --git a/tests/php/Activity/Provider/InvitationTest.php b/tests/php/Activity/Provider/InvitationTest.php index 2d9a44e5a5c..14e41cac44b 100644 --- a/tests/php/Activity/Provider/InvitationTest.php +++ b/tests/php/Activity/Provider/InvitationTest.php @@ -29,6 +29,7 @@ use OCA\Talk\Manager; use OCA\Talk\Room; use OCA\Talk\Service\AvatarService; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\IL10N; @@ -119,7 +120,7 @@ public function testParseThrowsWrongSubject(): void { ->willReturn(false); $provider = $this->getProvider(); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(UnknownActivityException::class); $provider->parse('en', $event); }