svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
917 stars 96 forks source link

multiClientMiddleware broken? Cannot read property 'request' of undefined #101

Open Slodin opened 5 years ago

Slodin commented 5 years ago

My code works with axiosMiddleware, but after I switched over to multiclent, everything went wrong. It keep on giving me

Cannot read property 'request' of undefined

It seems like it's not getting the request from the redux action in payload.

import {multiClientMiddleware} from 'redux-axios-middleware';

export default ReduxStore = createStore(
    rootReducer, 
    applyMiddleware(
        multiClientMiddleware(
            AxiosClient
        )
    )
)

AxiosClient = {
    default: {
      client: axios.create({
        baseURL: baseUrl,
        timeout: 6000,
        responseType: 'json',
      })
      options: defaultConfig
    },
    googleMaps: {
      client: axios.create({
        baseURL: baseGoogleMapAPI,
        timeout: 6000,
        responseType: 'json'
      })
    }
  }

const defaultConfig = {
  interceptors: {
    request: [{
      success: function ({getState, dispatch, getSourceAction}, req) {
        handleTokenAuth(req);
      },
      error: function ({getState, dispatch, getSourceAction}, error) {
        Promise.reject(error)
      }
    }
    ],
    response: [{
      success: function ({getState, dispatch, getSourceAction}, req) {
        handleAxiosSuccess(req);
      },
      error: function ({getState, dispatch, getSourceAction}, error) {
        handleAxiosError(error);
      }
    }
    ]
  }
}

Redux action, it pretty much dies here

export function getUser(){
    return {
        type: "GET_USER",
        payload: {
            client: 'default',
            request: {
                method: 'GET',
                url: '/auth/user'
            }
        }
    };
}