chargebee / chargebee-php

PHP library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=php
MIT License
72 stars 62 forks source link

No way to retrieve the 'retry-after' header in case of 429 OperationFailedException #52

Closed yched closed 2 months ago

yched commented 1 year ago

From the "Error handling" section of the API docs :

If you receive an HTTP 429 Too Many Requests error response to an API call, it means that the API requests for your Chargebee site have exceeded acceptable limits. Chargebee may also send a Retry-After header indicating the time duration to wait before sending a new request.

But on a HTTP 429 error, trhe Chargebee-php library throws an OperationFailedException, and offers no way to access the response headers, and thus no way to read the "Retry-After" value sent by Chargbee API.

cb-alish commented 3 months ago

Hi @yched, sorry for the delay in response. This has been fixed on the latest release, v3.28.0. You'll be able to access headers in the following manner. Please give it a try and let us know if you face any issues.

catch (APIError $e) {
        $errorHeaders = $e->getHeaders();
        $retryAfterHeaders = $errorHeaders['Retry-After'][0];
        echo $retryAfterHeaders . "\n";
}
yched commented 2 months ago

Tnanjs @cb-alish , this works great ! :+1:

cb-sriramthiagarajan commented 2 months ago

Thanks for the confirmation @yched 👍