2017-03-05 112 views
2

我使用express.js设置我的本地服务器,它只处理请求并返回简单消息。React Native中可能未处理的承诺拒绝网络错误

app.get('/hello', (req, res) => { 
    res.send('Hello world !'); 
}); 

我执行服务器并在网络浏览器上测试它,它工作正常。

只是我想在我的react-native应用程序上做到这一点。

这是我的action.js文件

import axios from 'axios'; 

exports.helloButtonPressAct = (email, password) => { 
    return function (dispatch) { 
     return axios.get('http://localhost:3000/hello') 
      .then(function (response) { 
       console.log(response); 

       // and create action obj here 
       // dispatch(someAction(...)) 
      }) 
      .catch(function (error) { 
       throw error; 
       console.log(error); 
      }); 
    }; 
}; 

它只返回catch()结果。

Possible Unhandled Promise Rejection (id: 0): Network Error Error: Network Error at createError ...

enter image description here

或许真的错了,但我找不到它是什么。

我该如何解决这个问题?

回答

相关问题