JavaEar 专注于收集分享传播有价值的技术资料

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?

1个回答

    最佳答案