makeomatic/redux-connect

Handle thrown errors in promise callbacks

Open

#108 aperta il 23 feb 2017

Vedi su GitHub
 (4 commenti) (3 reazioni) (0 assegnatari)JavaScript (73 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (550 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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);
}

Guida contributor