AcmeService Exception handling: Can't buffer() a payload more than once
vanoostrum opened this issue · 1 comments
In the class Kelunik/Acme/AcmeService
the following piece of code occurs on multiple occasions in slightly different forms:
try {
return Authorization::fromResponse($url, $response->getBody()->buffer());
} catch (\Throwable $_) {
throw $this->generateException($response, $response->getBody()->buffer());
}
This can lead to the following Exception: "Can't buffer() a payload more than once" in /vendor/amphp/byte-stream/src/Payload.php(96)
This happens when there is a response which cannot be parsed successfully. The method $response->getBody()->buffer()
is called twice in this situation, resulting in the error above.
A solution for this issue could be to first store the responseBuffer in a local variable, to avoid reading it twice:
$responseBuffer = $response->getBody()->buffer()
try {
return Authorization::fromResponse($url, responseBuffer);
} catch (\Throwable $_) {
throw $this->generateException($response, responseBuffer);
}
If you prefer I could make a pull request for this
Thanks for reporting! I guess this is new in the new major version of the http-client, as previously multiple buffer calls have been allowed.