Redux Action在reactjs中返回未定义和节点代理问题

时间:2018-11-07 21:06:53

标签: node.js reactjs redux react-redux

Error I get Given action "DID_FETCH_SUCCESS", reducer "did" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.

**My Action Class:**


/**
 * DID Search in progress.
 */
 export const didSearchIsLoading = isLoading => {
   return {
     type: DID_SEARCH_IS_LOADING,
     payload: isLoading
   }
};

/**
 * DID Search error.
 */
export const didSearchError = error => {
  return {
    type: DID_SEARCH_ERROR,
    payload: error
  }
};

/**
 * Payload is a list of DID's.
 */
 export const didSearchSuccess = (country, result) => {
   return {
     type: DID_SEARCH_SUCCESS,
     payload: {
       country,
       result
     }
   }
};

/**
 * Performs API call to search for DID's matching query params.
 */
 export const didSearchFetchData = (country, criteria) => {
   return (dispatch) => {
     dispatch(didSearchIsLoading(true));

     postDIDSearch(country, criteria)
     .then((data) => {
       dispatch(didSearchIsLoading(false));
       console.log('data',data)
       // If only one result
       if (data.dids.length == 1) {
          dispatch(didFetchSuccess(data.dids[0][country.toLowerCase()]))
          dispatch(push(`/console/did/${country}/${data.dids[0][country.toLowerCase()].e164}`));
       } else {
         dispatch(push('/console/did/search/result'));
         dispatch(didSearchSuccess(country, data));
       }
     })
     .catch(error => {
       dispatch(didSearchIsLoading(false));
       dispatch(didSearchError(error.message));
     })
   }
};


/*********************** DID-specific Action Creators *************************/
/**
 * Fetching of a specific DID/E164 in progress.
 */
 export const didIsLoading = isLoading => {
   return {
     type: DID_IS_LOADING,
     payload: isLoading
   }
};

/**
 * Successful fetch of DID/E164.
 * Payload is the DID.
 */
 export const didFetchSuccess = did => {
   console.log('did',did);
  return {
    type: DID_FETCH_SUCCESS,
    payload: did
  }
};

/**
 * Fetching error for a specific DID/E164.
 */
export const didFetchError = error => {
  return {
    type: DID_FETCH_ERROR,
    payload: error
  }
};


**My Reducer:**

import {DID_SEARCH_IS_LOADING, DID_SEARCH_ERROR, DID_SEARCH_SUCCESS,
DID_IS_LOADING, DID_IS_UPDATING, DID_FETCH_ERROR, DID_FETCH_SUCCESS, DID_UPDATE_ERROR,
DID_UPDATE_SUCCESS}
from '../actions/did.action';

export const searchIsLoading = (state = false, action) => {
  switch (action.type) {
    case DID_SEARCH_IS_LOADING:
      return action.payload
    default:
      return state
  }
}

export const searchSuccess = (state = {}, action) => {
  switch (action.type) {
    case DID_SEARCH_SUCCESS:
      return action.payload
    default:
      return state
  }
}

export const searchError = (state = null, action) => {
  switch (action.type) {
    case DID_SEARCH_ERROR:
      return action.payload
    default:
      return state
  }
}

export const didIsLoading = (state = false, action) => {
  switch (action.type) {
    case DID_IS_LOADING:
      return action.payload
    default:
      return state
  }
}

export const didIsUpdating = (state = false, action) => {
  switch (action.type) {
    case DID_IS_UPDATING:
      return action.payload
    default:
      return state
  }
}

export const didFetchError = (state = null, action) => {
  switch (action.type) {
    case DID_FETCH_ERROR:
      return action.payload
    default:
      return state
  }
}

export const didFetchSuccess = (state = {}, action) => {
  console.log('redstate',state);
  console.log('redpayload',action.payload);
  switch (action.type) {
    case DID_FETCH_SUCCESS:
      return action.payload
    default:
      return state
  }
}

export const didUpdateSuccess = (state = null, action) => {
  switch (action.type) {
    case DID_UPDATE_SUCCESS:
      return action.payload
    default:
      return state
  }
}

export const didUpdateError = (state = null, action) => {
  switch (action.type) {
    case DID_UPDATE_ERROR:
      return action.payload
    default:
      return state
  }
}

我最近遇到了两个问题。 1.我正在尝试获取数字,但它返回未定义的错误。当我尝试调试时,未定义会在didFetchSuccess中返回。到此为止,它已经包含了数据。 2.当我尝试进行任何搜索并且响应很大时,它会引发代理错误,例如无法从http://localhost:3000http://localhost:8002进行代理。节点上的ECONNRESET错误。

我已经正确定义了路由和代理。

代理错误:无法将localhost:3000的请求/ ossapi / v1 / number / US?search_availableonly = false&search_npanxx = 205_201代理到http://localhost:8002。 有关更多信息,请参见https://nodejs.org/api/errors.html#errors_common_system_errors(ECONNRESET)。

0 个答案:

没有答案