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

Possible Unhandled Promise Rejection (id: 0) #75

Open
dilipmukkapati opened this issue Dec 13, 2017 · 0 comments
Open

Possible Unhandled Promise Rejection (id: 0) #75

dilipmukkapati opened this issue Dec 13, 2017 · 0 comments

Comments

@dilipmukkapati
Copy link

dilipmukkapati commented Dec 13, 2017

Hi Guys thanks for the middleware library its really helpful.

Am facing issue when I receive success response from the server.

_FAIL works absolutely fine without error. But,

_SUCCESS is called and response is received as expected, but am getting a warning saying "possible unhandled promise Rejection (id: 1) TypeError: null is not a object (evaluating 'action.type') getStateForAction)"

Is it something you already faced, because promise is generated only by the middleware library for the action am performing.

Here is the config info:

const client = axios.create({ //all axios can be used, shown in axios documentation
    baseURL: 'http://192.168.5.10/CoreServices/',
    responseType: 'json'
});

const options = {
    interceptors: {
        request: [{
            success: ({getState, dispatch, getSourceAction}, req) => {
                if (getState() && getState().sessionReducer && getState().sessionReducer.token) {
                    req.headers['Authorization'] = 'Bearer ' + getState().sessionReducer.token
                }
                dispatch({
                    type: SHOW_LOADER
                });

                return req
            },
            error: ({getState, dispatch, getSourceAction}, req) => {
                dispatch({
                    type: HIDE_LOADER
                });

                return Promise.reject(req);
            }
        }],
        response: [{
            success: ({getState, dispatch, getSourceAction}, res) => {
                store.dispatch({
                    type: HIDE_LOADER
                });
                return res;
            },
            error: ({getState, dispatch, getSourceAction}, res) => {
                store.dispatch({
                    type: HIDE_LOADER
                });
                return Promise.reject(res);
            }
        }]
    }
};


switch (action.type) {
    case `${LOGIN}`:
        return {...state}
        break;
    case `${LOGIN}_SUCCESS`:
        return {...state, isLoggedIn: true}
        break;
    case `${LOGIN}_FAIL`:
        console.log('login failed!');
        if(action.error &&
            action.error.response &&
            action.error.response.data &&
            action.error.response.data.errors &&
            Array.isArray(action.error.response.data.errors) &&
            action.error.response.data.errors.length > 0) {
            return {...state, isLoggedIn: false, error: action.error.response.data.errors[0].message}
        } else {
            return {...state, error: 'test error from backend'}
        }
        break;
    case RESET_AUTHENTICATION_ERROR:
        return {...state, error: null}
        break;
    default:
        return {...state}
}

Please let me know if you have some info about this.

  • Dilip.
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