diff --git a/src/DTO/ShipmentCustomsItem.php b/src/DTO/ShipmentCustomsItem.php index dc7a485..79c120f 100644 --- a/src/DTO/ShipmentCustomsItem.php +++ b/src/DTO/ShipmentCustomsItem.php @@ -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'], diff --git a/src/ShipEngineClient.php b/src/ShipEngineClient.php index c26da53..66dea6a 100644 --- a/src/ShipEngineClient.php +++ b/src/ShipEngineClient.php @@ -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] @@ -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" . @@ -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();