Skip to content

Commit 3689fc8

Browse files
authored
Merge pull request #3344 from nextcloud/fix/activity-unknown-activity-exception
fix(activity): throw UnknownActivityException for unknown events
2 parents eb37509 + ff7ee09 commit 3689fc8

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/Activity/Provider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCA\Forms\Db\FormMapper;
1313
use OCA\Forms\Service\CirclesService;
14+
use OCP\Activity\Exceptions\UnknownActivityException;
1415
use OCP\Activity\IEvent;
1516
use OCP\Activity\IEventMerger;
1617
use OCP\Activity\IProvider;
@@ -44,12 +45,12 @@ public function __construct(
4445
* @param IEvent $event
4546
* @param IEvent|null $previousEvent
4647
* @return IEvent
47-
* @throws \InvalidArgumentException
48+
* @throws UnknownActivityException
4849
*/
4950
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
5051
// Throw Exception, if not our activity. Necessary for workflow of Activity-App.
5152
if ($event->getApp() !== $this->appName) {
52-
throw new \InvalidArgumentException();
53+
throw new UnknownActivityException();
5354
}
5455
$l10n = $this->l10nFactory->get($this->appName, $language);
5556

@@ -72,7 +73,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
7273
* Provide the translated string with placeholders
7374
* @param $subject The events subject
7475
* @return string
75-
* @throws \InvalidArgumentException
76+
* @throws UnknownActivityException
7677
*/
7778
public function getSubjectString(IL10N $l10n, string $subject): string {
7879
switch ($subject) {
@@ -90,7 +91,7 @@ public function getSubjectString(IL10N $l10n, string $subject): string {
9091

9192
default:
9293
$this->logger->warning('Some unknown activity has been found: ' . $subject);
93-
throw new \InvalidArgumentException();
94+
throw new UnknownActivityException();
9495
}
9596
}
9697

tests/Unit/Activity/ProviderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Forms\Db\Form;
1313
use OCA\Forms\Db\FormMapper;
1414
use OCA\Forms\Service\CirclesService;
15+
use OCP\Activity\Exceptions\UnknownActivityException;
1516
use OCP\Activity\IEvent;
1617
use OCP\Activity\IEventMerger;
1718
use OCP\AppFramework\Db\DoesNotExistException;
@@ -92,7 +93,7 @@ public function testWrongApp() {
9293
->method('getApp')
9394
->willReturn('someOtherApp');
9495

95-
$this->expectException(\InvalidArgumentException::class);
96+
$this->expectException(UnknownActivityException::class);
9697
$this->provider->parse('de_DE', $event);
9798
}
9899

@@ -199,7 +200,7 @@ public function testGetUnknownSubjectString() {
199200
$l10n->expects($this->never())
200201
->method('t');
201202

202-
$this->expectException(\InvalidArgumentException::class);
203+
$this->expectException(UnknownActivityException::class);
203204
$this->provider->getSubjectString($l10n, 'someUnknownSubject');
204205
}
205206

0 commit comments

Comments
 (0)