Exception handling¶
The following tree view describes how the exceptions used in this library depend on each other.
. \Exception
├── Firstred\PostNL\Exception\PostNLException
│ ├── Firstred\PostNL\Exception\ApiException
│ │ ├── Firstred\PostNL\Exception\ApiConnectionException
│ │ ├── Firstred\PostNL\Exception\CifDownException
│ │ ├── Firstred\PostNL\Exception\CifException
│ │ ├── Firstred\PostNL\Exception\NotFoundException
│ │ ├── Firstred\PostNL\Exception\ResponseException
│ │ └── Firstred\PostNL\Exception\ShipmentNotFoundException
│ ├── Firstred\PostNL\Exception\HttpClientException
│ └── Firstred\PostNL\Exception\InvalidArgumentException
│ ├── Firstred\PostNL\Exception\InvalidBarcodeException
│ ├── Firstred\PostNL\Exception\InvalidConfigurationException
│ ├── Firstred\PostNL\Exception\InvalidMethodException
│ ├── Firstred\PostNL\Exception\NotImplementedException
│ └── Firstred\PostNL\Exception\NotSupportedException
└── Psr\Cache\InvalidArgumentException
This library throws exceptions for errors that occur during a request.
In the event of an API error a
Firstred\PostNL\Exception\ApiException
is thrownuse Firstred\PostNL\Exception\ApiException; try { $postnl->getTimeframes(...); } catch (ApiException $e) { // ... }
A
Firstred\PostNL\Exception\ResponseException
exception is thrown when a response could not be understood by the library.All exceptions that occur in underlying HTTP Clients are handled by
Firstred\PostNL\Exception\HttpClientException
s.Invalid inputs are handled by the
Firstred\PostNL\Exception\InvalidArgumentException
exceptions.In case of caching problems due to invalid keys, a
Psr\Cache\InvalidArgumentException
is thrown. This could mean that the library is unable to utilize the configured caching library.
If you want to catch all exceptions thrown by this library be sure to catch both Firstred\PostNL\Exception\PostNLException
s and Psr\Cache\InvalidArgumentException
s.
use Firstred\PostNL\Exception\PostNLException;
use Psr\Cache\InvalidArgumentException as PsrCacheInvalidArgumentException;
try {
$postnl->getTimeframes(...);
} catch (PostNLException $e) {
// ...
} catch (PsrCacheInvalidArgumentException $e) {
// ...
}
use Firstred\PostNL\Exception\PostNLException;
use Psr\Cache\InvalidArgumentException as PsrCacheInvalidArgumentException;
try {
$postnl->getTimeframes(...);
} catch (PostNLException | PsrCacheInvalidArgumentException $e) {
// ...
}