brocoders / redux-async-connect

It allows you to request async data, store them in redux state and connect them to your react component.
645 stars 103 forks source link

catching exception #70

Closed greetclock closed 2 years ago

greetclock commented 8 years ago

Hi, I faced with the problem when a promise swallows exceptions.

I had this code:

@asyncConnect([{
  promise: ({store: {getState, dispatch}, params: {lectureId, moduleNumber}}) => {
    let state = getState();
    let lecture = state.activeLectures.list[lectureId].lecture; // HERE is an exception
    lecture = state.lectures.list[lecture];

    let lecturePromise = lecture ? Promise.resolve(lecture) : dispatch(loadSingle(lectureId));

    return lecturePromise.then(lecture => {
      let moduleId = typeof lecture.modules[moduleNumber] === 'string' ?
        lecture.modules[moduleNumber] : lecture.modules[moduleNumber]._id;

      return dispatch(loadSingleModule(moduleId));
    });
  }
}])

state.activeLectures.list[lectureId] is undefined, so it's impossible to read property lecture. The code i added catches exceptions like the one in my code and show a message to the console.

I know, this is not the best solution and i prefer to return the error object, but for some reason .catch and Promise.reject doesn't work. I propose to improve the code and then merge it

hanjukim commented 8 years ago

@cherurg I'm facing at this problem too. Did you find solution to return error object?

uschen commented 8 years ago

seems it got swallowed there.

what about dispatch an exception action in the .catch, or error as endGlobalLoad payload

probably a solution for the SSR 404 too.

hanjukim commented 8 years ago

@uschen Could you make a PR?