Skip to content

Commit

Permalink
Merge pull request #35321 from owncloud/stable10-catch-exception-on-d…
Browse files Browse the repository at this point in the history
…ecline

[Stable10] Catch internal server error from remote on decline
  • Loading branch information
phil-davis authored May 24, 2019
2 parents 3566cfc + c07b0ce commit 2798149
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 15 additions & 5 deletions apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
}
}
);
}
Expand Down
16 changes: 16 additions & 0 deletions apps/federatedfilesharing/tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2798149

Please sign in to comment.