在我的React Native应用程序中,即使请求成功,catch块也会始终执行

时间:2016-10-31 02:46:51

标签: react-native ios-simulator redux

在我的React Native应用程序中,我只是登录用户或创建帐户,但即使用户成功登录或成功添加到数据库,我的登录和注册功能的catch块也会始终执行。这意味着成功块(然后)和catch块都背靠背执行。

除了catch块错误之外,我还看到一些黄色框警告,说我的JS相对于TextInput组件太慢了。我不知道这些是否与catch块问题有关。

这个bug也影响了其他人,但我还没有听说过有人找到解决方案。我已经在邮递员中测试了我的登录和注册路线,他们按预期工作,没有问题。

以下是登录和注册操作创建者:

登录:

export const loginUser = ({ email, password }) => {
   const props = { email, password };
   return (dispatch) => {
     // notifies REDUX store that an ajax request is in progress
     dispatch({ type: types.LOGIN_USER_START });

     axios.post('http://localhost:3000/signin', props)
       .then(user => loginUserSuccess(dispatch, user))
       .catch(() => loginUserFail(dispatch));
   };
 };

注册:

export const signupUser = ({ email, password }) => {
  const props = { email, password };
  return (dispatch) => {
    // notifies REDUX store that an ajax request is in progress
    dispatch({ type: types.SIGNUP_USER_START });

    axios.post('http://localhost:3000/signup', props)
      .then(user => signupUserSuccess(dispatch, user))
      .catch(() => {
        signupUserFailed(dispatch);
      });
  };
};

1 个答案:

答案 0 :(得分:0)

您的错误发生在loginUserSuccess的某处。我应该使用catch(()=>而不是catch((err)=>而是对错误执行某些操作,例如console.log(err.stack),然后您就会确切地知道

  • 出了什么问题
  • 问题出在哪里
相关问题