Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible Unhandled Promise Rejection Network Error in React Native

I setup my local server using express.js, That simply handle request and return simple message.

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

I executed server and test it on web-browser, it works well.

Simply I want to do that on my react-native app.

this is my action.js file

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);
            });
    };
};

It only return catch() result.

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

enter image description here

Maybe something wrong but I couldn't find what is it.

How can I fix this?

like image 620
ton1 Avatar asked Mar 05 '17 05:03

ton1


1 Answers

Solved.

return axios.get('http://localhost:3000/hello')

to

return axios.get('http://10.0.0.2:3000/hello')

and It works.

In Android emulator, the localhost refers its device.

https://github.com/facebook/react-native/issues/10404

like image 72
ton1 Avatar answered Dec 15 '22 20:12

ton1