-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Labels
Description
When using and async requests CurlPromise seems to ignore the ErrorPlugin and throws the original exception instead. For example in case of 404 response ErrorPlugin is supposed to thrown ClientErrorException.
use Http\Client\Curl\Client as Curl;
use Http\Message\MessageFactory\DiactorosMessageFactory;
use Http\Message\StreamFactory\DiactorosStreamFactory;
use Http\Client\Common\Plugin\ErrorPlugin;
use Http\Client\Common\PluginClient;
use Psr\Http\Message\ResponseInterface;
$nosuch = (new DiactorosMessageFactory)->createRequest("GET", "http://google.com/nosuch");
$curl = new Curl(new DiactorosMessageFactory(), new DiactorosStreamFactory());
$client = new PluginClient($curl, [new ErrorPlugin]);
$promise = $client
->sendAsyncRequest($nosuch)
->then(function (ResponseInterface $response) {
print date("H:s") . " got foo\n";
return $response;
});
try {
$promise->wait();
} catch (\Exception $exception) {
print "async: " . get_class($exception) . "\n";
}
try {
$client->sendRequest($nosuch);
} catch (\Exception $exception) {
print "sync: " . get_class($exception) . "\n";
}
/*
async: Http\Client\Exception\RequestException
sync: Http\Client\Common\Exception\ClientErrorException
*/