From 9a26feb49536d502562a6777fa636c2ce39313e1 Mon Sep 17 00:00:00 2001 From: Dmitry Parkhomenko <157483149+parkhomenko-pp@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:27:18 +0000 Subject: [PATCH] ISSUE-239 fix checkout api exception getBody() on null --- lib/Checkout/CheckoutApiException.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Checkout/CheckoutApiException.php b/lib/Checkout/CheckoutApiException.php index 7366e3fb..2b5fe40c 100644 --- a/lib/Checkout/CheckoutApiException.php +++ b/lib/Checkout/CheckoutApiException.php @@ -21,13 +21,16 @@ class CheckoutApiException extends CheckoutException */ public static function from(RequestException $requestException) { - $body = json_decode($requestException->getResponse()->getBody()->getContents(), true); + $response = $requestException->getResponse(); + $ex = new CheckoutApiException(sprintf( "The API response status code (%s) does not indicate success.", $requestException->getCode() )); - $ex->error_details = $body; - $ex->http_metadata = CheckoutUtils::getHttpMetadata($requestException->getResponse()); + $ex->error_details = isset($response) + ? json_decode($response->getBody()->getContents(), true) + : []; + $ex->http_metadata = CheckoutUtils::getHttpMetadata($response); return $ex; } }