Skip to content

ErrorPlugin and sendAsyncRequest() incompatibility #27

Closed
@tuupola

Description

@tuupola

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
*/

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions