Skip to content

Commit 0b84595

Browse files
author
Quentin Schmick
authored
Fixing customs value check; Adding handling/rethrowing of rate limit exception (#19)
1 parent df89046 commit 0b84595

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/DTO/ShipmentCustomsItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(...$args)
2727
$temp = $temp[0];
2828
}
2929

30-
if (is_float($temp['value'])) {
30+
if (is_numeric($temp['value'])) {
3131
$args['value'] = [
3232
'currency' => 'usd',
3333
'amount' => $temp['value'],

src/ShipEngineClient.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private static function sendRequest(
189189
$response = null;
190190
self::incrementRequestCount($config);
191191

192+
$requestLog->occurred_at = now();
192193
$response = $client->send(
193194
$request,
194195
['timeout' => $config->timeout->s, 'http_errors' => false]
@@ -199,13 +200,12 @@ private static function sendRequest(
199200
if (self::responseIsRateLimit($requestLogResponse)) {
200201
throw new RateLimitExceededException(retryAfter: new DateInterval('PT1S'));
201202
}
203+
} catch (RateLimitExceededException $err) {
204+
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));
205+
206+
throw $err;
202207
} catch (Exception|Throwable $err) {
203-
if (config('shipengine.track_requests')) {
204-
$requestLog->response_code = $response?->getStatusCode();
205-
$requestLog->response = $requestLogResponse ?? null;
206-
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));
207-
$requestLog->save();
208-
}
208+
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));
209209

210210
throw new ShipEngineException(
211211
"An unknown error occurred while calling the ShipEngine $method API:\n" .
@@ -215,6 +215,12 @@ private static function sendRequest(
215215
'System',
216216
'Unspecified'
217217
);
218+
} finally {
219+
if (config('shipengine.track_requests')) {
220+
$requestLog->response_code = $response?->getStatusCode();
221+
$requestLog->response = $requestLogResponse ?? null;
222+
$requestLog->save();
223+
}
218224
}
219225

220226
$requestLog->response_code = $response->getStatusCode();

0 commit comments

Comments
 (0)