我发现$promise->wait()函数会抛出异常,我必须再次使用try-catch来处理异常。
$promise = $this->client->sendAsync($request);
$promise->then(
function ($response) use (...){
//do something
},
function ($exception) {
$this->logger->error("Failed " . $exception->getMessage());
}
);
try{
$promise->wait(true);
}catch(Exception $exception){
$this->logger->error("Failed " . $exception->getMessage());
}
错误信息将被记录器记录两次。 onrejected函数中有没有可以处理异常的方法?或者有更好的方法来处理此类异常吗?
这是我的错误: PHP 致命错误:未捕获的 GuzzleHttp\Exception\ClientException:客户端错误:...
非常感谢您的帮助。
这个我试过了
$promise->then(
//...
)->then(
//...
);
但不工作。
好吧,也许我明白了。 更换
try{
$promise->wait(true);
}catch(Exception $exception){
$this->logger->error("Failed " . $exception->getMessage());
}
与
Promise\Utils::settle($promise)->wait();
或
$promise->wait(false);