{"action":"created","issue":{"url":"https://api.github.com/repos/reactphp/http-client/issues/31","labels_url":"https://api.github.com/repos/reactphp/http-client/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/reactphp/http-client/issues/31/comments","events_url":"https://api.github.com/repos/reactphp/http-client/issues/31/events","html_url":"https://github.com/reactphp/http-client/pull/31","id":81428835,"number":31,"title":"Avoid hidding exceptions thrown in HttpClient\\Request error handlers","user":{"login":"arnaud-lb","id":365207,"avatar_url":"https://avatars.githubusercontent.com/u/365207?v=3","gravatar_id":"","url":"https://api.github.com/users/arnaud-lb","html_url":"https://github.com/arnaud-lb","followers_url":"https://api.github.com/users/arnaud-lb/followers","following_url":"https://api.github.com/users/arnaud-lb/following{/other_user}","gists_url":"https://api.github.com/users/arnaud-lb/gists{/gist_id}","starred_url":"https://api.github.com/users/arnaud-lb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnaud-lb/subscriptions","organizations_url":"https://api.github.com/users/arnaud-lb/orgs","repos_url":"https://api.github.com/users/arnaud-lb/repos","events_url":"https://api.github.com/users/arnaud-lb/events{/privacy}","received_events_url":"https://api.github.com/users/arnaud-lb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-27T12:29:05Z","updated_at":"2015-06-07T11:35:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/reactphp/http-client/pulls/31","html_url":"https://github.com/reactphp/http-client/pull/31","diff_url":"https://github.com/reactphp/http-client/pull/31.diff","patch_url":"https://github.com/reactphp/http-client/pull/31.patch"},"body":"`then()` catches exceptions, which is not desirable when its result is not returned.\r\n\r\nThe following code throws an exception in the 'error' event handler. However, the exception is caught because the event is fired in a `then()` callback.\r\n\r\nThis PR fixes this by changing a `then` to a `done`.\r\n\r\n``` php\r\n$requestData = new RequestData('GET', 'http://www.example.com');\r\n$request = new Request($this->connector, $requestData);\r\n\r\n$request->on('error', function () {\r\n    throw new \\Exception();\r\n});\r\n\r\n$request->end();\r\n```\r\n\r\nActual use case:\r\n\r\n``` php\r\n$requestData = new RequestData('GET', 'http://www.example.com');\r\n$request = new Request($this->connector, $requestData);\r\n\r\n$deferred = new Deferred();\r\n\r\n$request->on('error', function ($err) use ($deferred) {\r\n    $deferred->reject($err);\r\n});\r\n\r\n$deferred->done(); // Throws an exception if the deferred is rejected.\r\n                   // Without the PR, the exception is caught.\r\n\r\n$request->end();\r\n```"},"comment":{"url":"https://api.github.com/repos/reactphp/http-client/issues/comments/109741405","html_url":"https://github.com/reactphp/http-client/pull/31#issuecomment-109741405","issue_url":"https://api.github.com/repos/reactphp/http-client/issues/31","id":109741405,"user":{"login":"clue","id":776829,"avatar_url":"https://avatars.githubusercontent.com/u/776829?v=3","gravatar_id":"","url":"https://api.github.com/users/clue","html_url":"https://github.com/clue","followers_url":"https://api.github.com/users/clue/followers","following_url":"https://api.github.com/users/clue/following{/other_user}","gists_url":"https://api.github.com/users/clue/gists{/gist_id}","starred_url":"https://api.github.com/users/clue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clue/subscriptions","organizations_url":"https://api.github.com/users/clue/orgs","repos_url":"https://api.github.com/users/clue/repos","events_url":"https://api.github.com/users/clue/events{/privacy}","received_events_url":"https://api.github.com/users/clue/received_events","type":"User","site_admin":false},"created_at":"2015-06-07T11:35:13Z","updated_at":"2015-06-07T11:35:13Z","body":"Thanks for spotting! These could certainly introduce some subtle and hard to trace issues.\r\n\r\nAfaict you're trying to  throw` an `Exception` in the `data` (or `error`) event handler? I'm not quite sure this has been tested extensively. Also, I'm not quite sure *how* this should be handled ideally.\r\n\r\nCan you provide a simple gist that exhibits this?"}}