makeomatic/redux-connect

Handle thrown errors in promise callbacks

Open

#108 建立於 2017年2月23日

在 GitHub 查看
 (4 留言) (3 反應) (0 負責人)JavaScript (73 fork)batch import
enhancementhelp wanted

倉庫指標

Star
 (550 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

This line of code does not catch errors so instead they get lost in the event loop and the component never gets rendered correctly. Additionally, it's hard to catch and display the error in an isomorphic app.

Something like this would reproduce it:

@asyncConnect([{
  deferred: true,
  promise: () => {
    throw new Error('whoops, this was not supposed to happen');
  },
}])
class SomeComponent extends React.Component {
  ...
}

It should be fixable like this:

let promiseOrResult;
try {
  promiseOrResult = item.promise(rest);
} catch (error) {
  promiseOrResult = Promise.reject(error);
}

貢獻者指南