| Q |
A |
| Bug? |
yes |
| New Feature? |
no |
| Version |
guzzlehttp/guzzle 6.3.3 guzzlehttp/promises v1.3.1 guzzlehttp/psr7 1.4.2 php-http/guzzle6-adapter v1.1.1 |
Actual Behavior
If the first HTTP call (promise) returns HTTP >= 400 (which triggers and exception in Guzzle by default) then the adapter throws the exception for the first HTTP call instead it would return the result of all promises.
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
use GuzzleHttp\Psr7\Request;
$client = new Client(['base_uri' => 'http://httpbin.org/']);
$pluginClient = new \Http\Client\Common\PluginClient(
new Http\Adapter\Guzzle6\Client($client), []
);
// Initiate each request but do not block
$promises = [
'image' => $pluginClient->sendAsyncRequest(new Request('GET', 'status/404')),
'png' => $pluginClient->sendAsyncRequest(new Request('GET', 'status/200')),
'jpeg' => $pluginClient->sendAsyncRequest(new Request('GET', 'status/200')),
'webp' => $pluginClient->sendAsyncRequest(new Request('GET', 'status/404'))
];
try {
// Wait for the requests to complete, even if some of them fail
$results = Promise\settle($promises)->wait();
}
catch (\Exception $e) {
echo $e->getMessage();
}
exit(0);
Expected Behaviour
settle() should "Wait for the requests to complete, even if some of them fail". So even if the first HTTP call returns HTTP >= 400 an exception should not be thrown.
http://docs.guzzlephp.org/en/stable/quickstart.html#concurrent-requests
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
$client = new Client(['base_uri' => 'http://httpbin.org/']);
// Initiate each request but do not block
$promises = [
'image' => $client->getAsync('status/404'),
'png' => $client->getAsync('status/200'),
'jpeg' => $client->getAsync('status/200'),
'webp' => $client->getAsync('status/404')
];
try {
// Wait for the requests to complete, even if some of them fail
$results = Promise\settle($promises)->wait();
}
catch (\Exception $e) {
echo $e->getMessage();
}
exit(0);
Steps to Reproduce
See the code snippets above.
Possible Solutions
For the first sight it seems the adapter should also wrap the result of all promises to a Promise object and return that instead of returning the results directly. At least this is what Guzzle Promise's working code indicates for me.
https://github.com/guzzle/promises/blob/v1.3.1/src/Promise.php#L69
Actual Behavior
If the first HTTP call (promise) returns HTTP >= 400 (which triggers and exception in Guzzle by default) then the adapter throws the exception for the first HTTP call instead it would return the result of all promises.
Expected Behaviour
settle() should "Wait for the requests to complete, even if some of them fail". So even if the first HTTP call returns HTTP >= 400 an exception should not be thrown.
http://docs.guzzlephp.org/en/stable/quickstart.html#concurrent-requests
Steps to Reproduce
See the code snippets above.
Possible Solutions
For the first sight it seems the adapter should also wrap the result of all promises to a Promise object and return that instead of returning the results directly. At least this is what Guzzle Promise's working code indicates for me.
https://github.com/guzzle/promises/blob/v1.3.1/src/Promise.php#L69