goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 323 forks source link

Rejecting promise of fetching via sources #619

Closed vincentschroeder closed 8 years ago

vincentschroeder commented 8 years ago

I want to handle an rejection of the VideoStore e.g. when the API is not reachable. Unfortunately I don't get the Promise I try to reject when I use VideoStore.fetchVideoById which is defined via decorators in my VideoStore. How can I handle this?

Fetching:

VideoStore.fetchVideoById(videoId).then((res) =>{
}).catch((err)=>{
});

VideoSource:

const VideoSource = {
    fetchVideoById: {
        remote(state, videoId) {
            return fetch(`/videos/${videoId}`).then((response) => {
                console.log(response.ok);
                if(response.ok){
                    return response.json();
                }else{
                    return Promise.reject('no video available.');
                }
            });
        },
        success: VideoActions.fetchVideoByIdSuccess,
        error: VideoActions.fetchVideoByIdError
    }
};
export default VideoSource;
goatslacker commented 8 years ago

Can you handle it in the error action?

Don't use a decorator?

Your first example looks fine.