diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index e89305162cd7..f59b30ab8719 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -21,6 +21,7 @@ namespace OCA\FederatedFileSharing\AppInfo; +use GuzzleHttp\Exception\ServerException; use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\Command\PollIncomingShares; use OCA\FederatedFileSharing\Controller\OcmController; @@ -34,6 +35,7 @@ use OCA\FederatedFileSharing\Ocm\Permissions; use OCA\FederatedFileSharing\TokenHandler; use OCP\AppFramework\App; +use OCP\AppFramework\Http; use OCP\Share\Events\AcceptShare; use OCP\Share\Events\DeclineShare; @@ -259,11 +261,19 @@ function (AcceptShare $event) use ($container) { function (DeclineShare $event) use ($container) { /** @var Notifications $notifications */ $notifications = $container->query('Notifications'); - $notifications->sendDeclineShare( - $event->getRemote(), - $event->getRemoteId(), - $event->getShareToken() - ); + try { + $notifications->sendDeclineShare( + $event->getRemote(), + $event->getRemoteId(), + $event->getShareToken() + ); + } catch (ServerException $e) { + // ownCloud lower than 10.2 responded with Internal Server Error + // on declining non-existing share. It can't be caught outside the closure + if ($e->getCode() !== Http::STATUS_INTERNAL_SERVER_ERROR) { + throw $e; + } + } } ); } diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php index 47ad6797043f..15dfa04e4173 100644 --- a/apps/federatedfilesharing/tests/NotificationsTest.php +++ b/apps/federatedfilesharing/tests/NotificationsTest.php @@ -34,6 +34,7 @@ use OCP\Http\Client\IResponse; use OCP\IConfig; use OCA\FederatedFileSharing\BackgroundJob\RetryJob; +use OCP\Share\Events\DeclineShare; class NotificationsTest extends \Test\TestCase { @@ -200,4 +201,19 @@ function ($options) { ] ); } + + public function testDeclineEvent() { + $dispatcher = \OC::$server->getEventDispatcher(); + $event = $dispatcher->dispatch( + DeclineShare::class, + new DeclineShare( + [ + 'remote_id' => '4354353', + 'remote' => 'http://localhost', + 'share_token' => 'ohno' + ] + ) + ); + $this->assertInstanceOf(DeclineShare::class, $event); + } }