|
12 | 12 | use ParcelTrap\DTOs\TrackingDetails; |
13 | 13 | use ParcelTrap\Enums\Status; |
14 | 14 | use ParcelTrap\Exceptions\ApiAuthenticationFailedException; |
15 | | -use RuntimeException; |
| 15 | +use ParcelTrap\USPS\Exceptions\USPSErrorResponseException; |
16 | 16 | use SimpleXMLElement; |
17 | 17 |
|
18 | 18 | class USPS implements Driver |
@@ -52,17 +52,18 @@ public function find(string $identifier, array $parameters = []): TrackingDetail |
52 | 52 | simplexml_load_string($this->getCleanedBody($response->getBody()->getContents())) |
53 | 53 | ), true, 512, JSON_THROW_ON_ERROR); |
54 | 54 |
|
55 | | - if ( |
56 | | - isset($json['Description']) && |
57 | | - str_starts_with((string) $json['Description'], 'API Authorization failure') |
58 | | - ) { |
59 | | - throw new ApiAuthenticationFailedException($this); |
| 55 | + if (isset($json['Description'])) { |
| 56 | + throw str_starts_with((string) $json['Description'], 'API Authorization failure') ? |
| 57 | + new ApiAuthenticationFailedException($this) : |
| 58 | + new USPSErrorResponseException((string) $json['Description']); |
60 | 59 | } |
61 | 60 |
|
62 | | - assert(isset($json['TrackInfo']), 'The tracking information is missing from the response'); |
| 61 | + if (! isset($json['TrackInfo'])) { |
| 62 | + throw new USPSErrorResponseException('The tracking information is missing from the response'); |
| 63 | + } |
63 | 64 |
|
64 | 65 | if (isset($json['TrackInfo']['Error']['Description'])) { |
65 | | - throw new RuntimeException((string) $json['TrackInfo']['Error']['Description']); |
| 66 | + throw new USPSErrorResponseException((string) $json['TrackInfo']['Error']['Description']); |
66 | 67 | } |
67 | 68 |
|
68 | 69 | $json = $json['TrackInfo']; |
|
0 commit comments