{"action":"created","issue":{"url":"https://api.github.com/repos/spoike/refluxjs/issues/275","labels_url":"https://api.github.com/repos/spoike/refluxjs/issues/275/labels{/name}","comments_url":"https://api.github.com/repos/spoike/refluxjs/issues/275/comments","events_url":"https://api.github.com/repos/spoike/refluxjs/issues/275/events","html_url":"https://github.com/spoike/refluxjs/issues/275","id":59563553,"number":275,"title":"Rejected promises not able to be caught correctly","user":{"login":"cmwelsh","id":86490,"avatar_url":"https://avatars.githubusercontent.com/u/86490?v=3","gravatar_id":"","url":"https://api.github.com/users/cmwelsh","html_url":"https://github.com/cmwelsh","followers_url":"https://api.github.com/users/cmwelsh/followers","following_url":"https://api.github.com/users/cmwelsh/following{/other_user}","gists_url":"https://api.github.com/users/cmwelsh/gists{/gist_id}","starred_url":"https://api.github.com/users/cmwelsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmwelsh/subscriptions","organizations_url":"https://api.github.com/users/cmwelsh/orgs","repos_url":"https://api.github.com/users/cmwelsh/repos","events_url":"https://api.github.com/users/cmwelsh/events{/privacy}","received_events_url":"https://api.github.com/users/cmwelsh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-02T22:38:24Z","updated_at":"2015-03-03T00:08:47Z","closed_at":null,"body":"I'm using `listenAndPromise` and besides the extensive boilerplate that seems to be required, the most annoying thing is that Bluebird is calling `Bluebird.onPossiblyUnhandledRejection` even though I have a `.catch` handler.\r\n\r\n    Reflux.createStore({\r\n        init: function () {\r\n            myActions.saveForm.listenAndPromise(this.onSaveForm.bind(this));\r\n        },\r\n        onSaveForm: function () {\r\n            return new Bluebird(function (resolve, reject) {\r\n                throw new ValidationError();\r\n            });\r\n        }\r\n    });\r\n\r\nIn my component\r\n\r\n    myActions.saveForm.triggerPromise()\r\n    .catch(function (e) {\r\n        console.log('caught error');\r\n    });\r\n\r\nThe console prints `caught error` but the global unhandled rejection handler is still firing...\r\n\r\nHonestly, I'm not sure if I'm doing this right or if anyone actually uses promises with Reflux..."},"comment":{"url":"https://api.github.com/repos/spoike/refluxjs/issues/comments/76859285","html_url":"https://github.com/spoike/refluxjs/issues/275#issuecomment-76859285","issue_url":"https://api.github.com/repos/spoike/refluxjs/issues/275","id":76859285,"user":{"login":"jankuca","id":367262,"avatar_url":"https://avatars.githubusercontent.com/u/367262?v=3","gravatar_id":"","url":"https://api.github.com/users/jankuca","html_url":"https://github.com/jankuca","followers_url":"https://api.github.com/users/jankuca/followers","following_url":"https://api.github.com/users/jankuca/following{/other_user}","gists_url":"https://api.github.com/users/jankuca/gists{/gist_id}","starred_url":"https://api.github.com/users/jankuca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankuca/subscriptions","organizations_url":"https://api.github.com/users/jankuca/orgs","repos_url":"https://api.github.com/users/jankuca/repos","events_url":"https://api.github.com/users/jankuca/events{/privacy}","received_events_url":"https://api.github.com/users/jankuca/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T00:08:47Z","updated_at":"2015-03-03T00:08:47Z","body":"I'm not sure about Bluebird. I looked over its implementation and it should work fine. It throws an \"unhandled promise rejection\" error in Chrome 40 with the native Promise.\r\n\r\nI managed to fix the issue by providing the `#then()` method of the promise returned by the action listener (`onSaveForm`) with both callbacks – onresolve and onreject. Here is how Reflux implements `#listenAndPromise()`:\r\n\r\n```\r\nlistenAndPromise(listener) {\r\n  var promise = listener();\r\n  promise.then(onResolve);\r\n  promise.catch(onReject);\r\n});\r\n```\r\n\r\nI don't know if there's a bug in the native Promise implementation and frankly I'm too sleepy to even care enough but if you merge the `then` and `catch` calls, it works just as it should:\r\n\r\n```\r\nlistenAndPromise(listener) {\r\n  var promise = listener();\r\n  promise.then(onResolve, onReject);\r\n});\r\n```\r\n\r\nThis is thus closely related to #265. The fix has been proposed as https://github.com/Turbo87/refluxjs/commit/62f2f011d910ca53ad1996b122094cf0ff83624a."}}