Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rejected promise does not fail state entry #25

Closed
consultwithmike opened this issue Jan 31, 2017 · 1 comment
Closed

Rejected promise does not fail state entry #25

consultwithmike opened this issue Jan 31, 2017 · 1 comment

Comments

@consultwithmike
Copy link

consultwithmike commented Jan 31, 2017

I have a state configured like this:

{
    name: 'home',
    url: '/',
    component: DashboardContainer,
    resolve: [
        {
            token: 'currentUser',
            resolveFn: () => store.dispatch(getCurrentUser())
                .then(res => {
                    if (!res.value) {
                        throw new Error('The current user could not be identified.');
                    }
                    // debugger;
                })
                .catch(err => {
                    // debugger;
                })
        }
    ],
    onEnter: () => {
        // debugger;
    },
    onExit: () => {
        // debugger;
    }
},

The getCurrentUser action looks like this:

return {
    type: GET_CURRENT_USER,
    payload: ax.request({
        url: urlJoin(
            config.portal.url,
            'api/CommonApi/GetCurrentUser'
        ),
        method: 'get',
        maxRedirects: 0
    }).then(res => {
        // debugger;
        if (!(res.data && res.data.clientId)) {
            throw new Error('The current user could not be identified.');
        }
    }).catch(err => {
        console.warn(err);
    })
};

When walking through this transition, I get to the debugger in the getCurrentUser action and throw the Error because we didn't get the user back. This then executes the console.warn(err). Then it executes the then of the store.dispatch promise, which subsequently bubbles that error and hits the debugger in the catch of the store.dispatch promise.

However, even though the promise is being failed, the onEnter is still firing for this state and the state is being rendered; what I'd like to do is navigate to the Login state.

What did I do wrong here?

@consultwithmike
Copy link
Author

UPDATE I stopped the entry of the state by executing throw new Error() inside the catch of the dispatch promise that was returned. Now I guess I just need to figure out how to redirect to the Login state when that happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant