Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Call to a member function getBody() on null #239

Closed
parkhomenko-pp opened this issue Feb 28, 2024 · 2 comments
Closed

Call to a member function getBody() on null #239

parkhomenko-pp opened this issue Feb 28, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request improvement Improve existing code

Comments

@parkhomenko-pp
Copy link
Contributor

parkhomenko-pp commented Feb 28, 2024

Description

RequestException::getResponse function ALWAYS (vendor/guzzlehttp/guzzle/src/Exception/ConnectException.php) return a null value when the request fails.

Possible solution

<?php

namespace Checkout;

use GuzzleHttp\Exception\RequestException;

class CheckoutApiException extends CheckoutException
{
    /**
     * @var array
     */
    public $error_details;
    /**
     * @var HttpMetadata
     */
    public $http_metadata;

    /**
     * @param RequestException $requestException
     * @return CheckoutApiException
     */
    public static function from(RequestException $requestException)
    {
        $response = $requestException->getResponse();

        $ex = new CheckoutApiException(sprintf(
            "The API response status code (%s) does not indicate success.",
            $requestException->getCode()
        ));
        $ex->error_details = isset($response) ? json_decode($response->getBody()->getContents(), true) : [];;
        $ex->http_metadata = CheckoutUtils::getHttpMetadata($response);
        return $ex;
    }
}

Additional information

Error: Call to a member function getBody() on null

  • /vendor/checkout/checkout-sdk-php/lib/Checkout/CheckoutApiException.php(24): Checkout\CheckoutApiException::from
  • /vendor/checkout/checkout-sdk-php/lib/Checkout/ApiClient.php(192): Checkout\ApiClient::invoke
  • /vendor/checkout/checkout-sdk-php/lib/Checkout/ApiClient.php(54): Checkout\ApiClient::post
  • /vendor/checkout/checkout-sdk-php/lib/Checkout/Payments/Hosted/HostedPaymentsClient.php(38): Checkout\Payments\Hosted\HostedPaymentsClient::createHostedPaymentsPageSession
@armando-rodriguez-cko armando-rodriguez-cko self-assigned this Feb 28, 2024
@armando-rodriguez-cko armando-rodriguez-cko added enhancement New feature or request improvement Improve existing code labels Feb 28, 2024
@armando-rodriguez-cko
Copy link
Contributor

Thank you @parkhomenko-pp! We will implement it in the next release, do you want to propose a PR with your changes?

@parkhomenko-pp
Copy link
Contributor Author

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request improvement Improve existing code
Development

No branches or pull requests

2 participants