From efb54452e8cd62fd9e3e6f06cfd640afd952edf7 Mon Sep 17 00:00:00 2001 From: Dmitry Parkhomenko <157483149+parkhomenko-pp@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:49:59 +0000 Subject: [PATCH] ISSUE-239 fix getBody on null --- lib/Checkout/CheckoutApiException.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Checkout/CheckoutApiException.php b/lib/Checkout/CheckoutApiException.php index 7366e3fb..25ba195b 100644 --- a/lib/Checkout/CheckoutApiException.php +++ b/lib/Checkout/CheckoutApiException.php @@ -21,13 +21,17 @@ 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; } }