{"action":"opened","issue":{"url":"https://api.github.com/repos/php-http/curl-client/issues/27","repository_url":"https://api.github.com/repos/php-http/curl-client","labels_url":"https://api.github.com/repos/php-http/curl-client/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/php-http/curl-client/issues/27/comments","events_url":"https://api.github.com/repos/php-http/curl-client/issues/27/events","html_url":"https://github.com/php-http/curl-client/issues/27","id":188537399,"number":27,"title":"ErrorPlugin and sendAsyncRequest() incompatibility","user":{"login":"tuupola","id":21913,"avatar_url":"https://avatars.githubusercontent.com/u/21913?v=3","gravatar_id":"","url":"https://api.github.com/users/tuupola","html_url":"https://github.com/tuupola","followers_url":"https://api.github.com/users/tuupola/followers","following_url":"https://api.github.com/users/tuupola/following{/other_user}","gists_url":"https://api.github.com/users/tuupola/gists{/gist_id}","starred_url":"https://api.github.com/users/tuupola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuupola/subscriptions","organizations_url":"https://api.github.com/users/tuupola/orgs","repos_url":"https://api.github.com/users/tuupola/repos","events_url":"https://api.github.com/users/tuupola/events{/privacy}","received_events_url":"https://api.github.com/users/tuupola/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-10T15:26:09Z","updated_at":"2016-11-10T15:26:09Z","closed_at":null,"body":"When using and async requests `CurlPromise` seems to  ignore the `ErrorPlugin` and [throws the original exception](https://github.com/php-http/curl-client/blob/master/src/CurlPromise.php#L101) instead. For example in case of `404` response `ErrorPlugin` is supposed to thrown `ClientErrorException`.\r\n\r\n```php\r\n$nosuch = (new DiactorosMessageFactory)->createRequest(\"GET\", \"http://google.com/nosuch\");\r\n$curl = new Client(new DiactorosMessageFactory(), new DiactorosStreamFactory());\r\n$client = new PluginClient($curl, [new ErrorPlugin]);\r\n\r\n$promise = $client\r\n    ->sendAsyncRequest($nosuch)\r\n    ->then(function (ResponseInterface $response) {\r\n        print date(\"H:s\") . \" got foo\\n\";\r\n        return $response;\r\n    });\r\n\r\ntry {\r\n    $promise->wait();\r\n} catch (\\Exception $exception) {\r\n    print \"async: \" . get_class($exception) . \"\\n\";\r\n}\r\n\r\ntry {\r\n    $client->sendRequest($nosuch);\r\n} catch (\\Exception $exception) {\r\n    print \"sync: \" . get_class($exception) . \"\\n\";\r\n}\r\n\r\n/* \r\nasync: Http\\Client\\Exception\\RequestException\r\nsync: Http\\Client\\Common\\Exception\\ClientErrorException\r\n*/\r\n```"}}
{"actor":{"display_login":"tuupola"}}