Skip to content

Commit

Permalink
Fixing customs value check; Adding handling/rethrowing of rate limit …
Browse files Browse the repository at this point in the history
…exception (#19)
  • Loading branch information
Quentin Schmick authored Aug 8, 2022
1 parent df89046 commit 0b84595
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/DTO/ShipmentCustomsItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(...$args)
$temp = $temp[0];
}

if (is_float($temp['value'])) {
if (is_numeric($temp['value'])) {
$args['value'] = [
'currency' => 'usd',
'amount' => $temp['value'],
Expand Down
18 changes: 12 additions & 6 deletions src/ShipEngineClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private static function sendRequest(
$response = null;
self::incrementRequestCount($config);

$requestLog->occurred_at = now();
$response = $client->send(
$request,
['timeout' => $config->timeout->s, 'http_errors' => false]
Expand All @@ -199,13 +200,12 @@ private static function sendRequest(
if (self::responseIsRateLimit($requestLogResponse)) {
throw new RateLimitExceededException(retryAfter: new DateInterval('PT1S'));
}
} catch (RateLimitExceededException $err) {
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));

throw $err;
} catch (Exception|Throwable $err) {
if (config('shipengine.track_requests')) {
$requestLog->response_code = $response?->getStatusCode();
$requestLog->response = $requestLogResponse ?? null;
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));
$requestLog->save();
}
$requestLog->exception = substr($err->getMessage(), 0, config('shipengine.request_log_table_exception_length'));

throw new ShipEngineException(
"An unknown error occurred while calling the ShipEngine $method API:\n" .
Expand All @@ -215,6 +215,12 @@ private static function sendRequest(
'System',
'Unspecified'
);
} finally {
if (config('shipengine.track_requests')) {
$requestLog->response_code = $response?->getStatusCode();
$requestLog->response = $requestLogResponse ?? null;
$requestLog->save();
}
}

$requestLog->response_code = $response->getStatusCode();
Expand Down

0 comments on commit 0b84595

Please sign in to comment.