I need to get response from async request and retry request if it's not successful. I'm trying to test with printing message in log file if exception is called, but I'm not getting this error message. What I tried so far -> I followed this link: https://github.com/reactphp/promise#how-promise-forwarding-works
$promise = Api::async()->get($url)->then(
function ($result) {
$this->handleResult($result);
}
)->otherwise(function (\Exception $x) {
// Propagate the rejection
info('error');
throw $x;
});
$promise->wait();
$promise = Api::async()->get($url)->then(
function ($result) {
$this->handleResult($result);
}
)->then(function ($result) {
info('error');
throw new \Exception($result);
})->otherwise(function (\Exception $result) {
// Handle the rejection, and don't propagate.
// This is like catch without a rethrow
info('error');
return $result->getMessage();
})
->then(function ($result) {
info('error');
});
$promise->wait();
These two I tried from this docs: https://docs.php-http.org/en/latest/components/promise.html
$promise = Api::async()->get($url)->then(
function ($result) {
$this->handleResult($result);
}
);
try {
$promise->wait();
} catch (\Exception $exception) {
info('error');
}
$promise = Api::async()->get($url)->then(
// The success callback
function (ResponseInterface $res) {
},
function (\Exception $e) {
info('error');
}
);
$promise->wait();