Skip to content

Commit

Permalink
Merge pull request #7 from genkgo/convert_apple_exception
Browse files Browse the repository at this point in the history
convert apple exception
  • Loading branch information
frederikbosch authored Feb 10, 2021
2 parents c32c26c + 6224aee commit 041d833
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 12 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Genkgo\Push\Exception;

use Exception;

class ApplePortalException extends Exception
final class ConnectionException extends AbstractException
{
}
8 changes: 8 additions & 0 deletions src/Exception/InvalidMessageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);

namespace Genkgo\Push\Exception;

final class InvalidMessageException extends AbstractException
{
}
8 changes: 8 additions & 0 deletions src/Exception/InvalidRecipientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);

namespace Genkgo\Push\Exception;

final class InvalidRecipientException extends AbstractException
{
}
75 changes: 74 additions & 1 deletion src/Sender/AppleApnSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
namespace Genkgo\Push\Sender;

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Exception\SendNotification\BadCertificateEnvironmentException;
use Apple\ApnPush\Exception\SendNotification\BadCertificateException;
use Apple\ApnPush\Exception\SendNotification\BadDeviceTokenException;
use Apple\ApnPush\Exception\SendNotification\BadExpirationDateException;
use Apple\ApnPush\Exception\SendNotification\BadMessageIdException;
use Apple\ApnPush\Exception\SendNotification\BadPathException;
use Apple\ApnPush\Exception\SendNotification\BadPriorityException;
use Apple\ApnPush\Exception\SendNotification\BadTopicException;
use Apple\ApnPush\Exception\SendNotification\DeviceTokenNotForTopicException;
use Apple\ApnPush\Exception\SendNotification\DuplicateHeadersException;
use Apple\ApnPush\Exception\SendNotification\ExpiredProviderTokenException;
use Apple\ApnPush\Exception\SendNotification\ForbiddenException;
use Apple\ApnPush\Exception\SendNotification\IdleTimeoutException;
use Apple\ApnPush\Exception\SendNotification\InvalidProviderTokenException;
use Apple\ApnPush\Exception\SendNotification\MethodNotAllowedException;
use Apple\ApnPush\Exception\SendNotification\MissingDeviceTokenException;
use Apple\ApnPush\Exception\SendNotification\MissingProviderTokenException;
use Apple\ApnPush\Exception\SendNotification\MissingTopicException;
use Apple\ApnPush\Exception\SendNotification\PayloadEmptyException;
use Apple\ApnPush\Exception\SendNotification\TopicDisallowedException;
use Apple\ApnPush\Exception\SendNotification\UndefinedErrorException;
use Apple\ApnPush\Exception\SendNotification\UnregisteredException;
use Apple\ApnPush\Model\Alert;
use Apple\ApnPush\Model\Aps;
use Apple\ApnPush\Model\DeviceToken;
Expand All @@ -14,6 +36,11 @@
use Apple\ApnPush\Sender\Builder\Http20Builder;
use Apple\ApnPush\Sender\SenderInterface as AppleSender;
use Genkgo\Push\Apn\JwtAuthenticator;
use Genkgo\Push\Exception\ConnectionException;
use Genkgo\Push\Exception\ForbiddenToSendMessageException;
use Genkgo\Push\Exception\InvalidMessageException;
use Genkgo\Push\Exception\InvalidRecipientException;
use Genkgo\Push\Exception\UnknownRecipientException;
use Genkgo\Push\Message;
use Genkgo\Push\Recipient\AppleDeviceRecipient;
use Genkgo\Push\RecipientInterface;
Expand Down Expand Up @@ -77,7 +104,53 @@ public function send(Message $message, RecipientInterface $recipient): void
$notification = new Notification($payload);
$receiver = new Receiver(new DeviceToken($recipient->getToken()), $this->bundleId);

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

/**
Expand Down

0 comments on commit 041d833

Please sign in to comment.