Skip to content

Commit

Permalink
improve catching apn exceptions and converting to local exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Mar 22, 2022
1 parent de67774 commit e0bbb2d
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/Sender/AppleApnSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,54 +102,59 @@ public function send(Message $message, RecipientInterface $recipient): void
}

$notification = new Notification($payload);
$receiver = new Receiver(new DeviceToken($recipient->getToken()), $this->bundleId);

try {
$receiver = new Receiver(new DeviceToken($recipient->getToken()), $this->bundleId);
} catch (\InvalidArgumentException $e) {
throw new InvalidRecipientException($e->getMessage(), $e->getCode(), $e);
}

try {
$this->sender->send($receiver, $notification, $this->sandbox);
} catch (UnregisteredException $e) {
throw new UnknownRecipientException($e->getMessage());
throw new UnknownRecipientException($e->getMessage(), $e->getCode(), $e);
} catch (BadDeviceTokenException $e) {
throw new InvalidRecipientException($e->getMessage());
throw new InvalidRecipientException($e->getMessage(), $e->getCode(), $e);
} catch (BadExpirationDateException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadMessageIdException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadPriorityException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadTopicException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (DeviceTokenNotForTopicException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (DuplicateHeadersException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (IdleTimeoutException $e) {
throw new ConnectionException($e->getMessage());
throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
} catch (MissingDeviceTokenException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (MissingTopicException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (PayloadEmptyException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (TopicDisallowedException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadCertificateException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadCertificateEnvironmentException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (ExpiredProviderTokenException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (ForbiddenException $e) {
throw new ForbiddenToSendMessageException($e->getMessage());
throw new ForbiddenToSendMessageException($e->getMessage(), $e->getCode(), $e);
} catch (InvalidProviderTokenException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (MissingProviderTokenException $e) {
throw new InvalidMessageException($e->getMessage());
throw new InvalidMessageException($e->getMessage(), $e->getCode(), $e);
} catch (BadPathException $e) {
throw new ConnectionException($e->getMessage());
throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
} catch (MethodNotAllowedException $e) {
throw new ConnectionException($e->getMessage());
throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
} catch (UndefinedErrorException $e) {
throw new ConnectionException($e->getMessage());
throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
}
}

Expand Down

0 comments on commit e0bbb2d

Please sign in to comment.