From e0bbb2df2b782b872548d6dfdb1fd56ded3fd76b Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Tue, 22 Mar 2022 22:50:19 +0100 Subject: [PATCH] improve catching apn exceptions and converting to local exceptions --- src/Sender/AppleApnSender.php | 51 +++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/Sender/AppleApnSender.php b/src/Sender/AppleApnSender.php index b5a8077..5f0873f 100644 --- a/src/Sender/AppleApnSender.php +++ b/src/Sender/AppleApnSender.php @@ -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); } }