diff --git a/lib/PushTransports/WebPushTransport.php b/lib/PushTransports/WebPushTransport.php index 6a8f3f4..ebd638a 100644 --- a/lib/PushTransports/WebPushTransport.php +++ b/lib/PushTransports/WebPushTransport.php @@ -28,6 +28,7 @@ namespace OCA\DavPush\PushTransports; use OCA\DavPush\Transport\Transport; use OCA\DavPush\Service\WebPushSubscriptionService; +use OCA\DavPush\Errors\WebPushSubscriptionNotFound; use Sabre\Xml\Service; @@ -96,10 +97,14 @@ class WebPushTransport extends Transport { $result = file_get_contents($data["pushResource"], false, $context); } - public function getSubscriptionIdFromOptions($options): int { + public function getSubscriptionIdFromOptions($options): ?int { ['pushResource' => $pushResource] = $this->parseOptions($options); - return $this->webPushSubscriptionService->findByPushResource($pushResource)->getSubscriptionId(); + try { + return $this->webPushSubscriptionService->findByPushResource($pushResource)->getSubscriptionId(); + } catch (WebPushSubscriptionNotFound $e) { + return null; + } } public function updateSubscription($subsciptionId, $options) { diff --git a/lib/Transport/Transport.php b/lib/Transport/Transport.php index 5e36c85..eb4bce8 100644 --- a/lib/Transport/Transport.php +++ b/lib/Transport/Transport.php @@ -62,7 +62,7 @@ abstract class Transport { // Transport needs to be able to map subscription options back to a subscription id. // API Requests to create and update a subscription are the same, therefore if a subscription id is associated with the given options the subscription is updated, otherwise a new subscription is added. // Which option(s) uniquely identify a subscription is implementation specific. - abstract public function getSubscriptionIdFromOptions($options): int; + abstract public function getSubscriptionIdFromOptions($options): ?int; // Change mutable options of the subscription (if any exist) abstract public function updateSubscription($subsciptionId, $options);