Axios请求在React-Native中返回错误

时间:2019-04-08 01:20:59

标签: reactjs react-native axios

我在React内置的Web应用程序中使用了相同的功能。但是,当我在React-Native中使用它时(我是React-Native的新手),如果我在捕获中console.log(err)并收到以下错误,则会收到网络错误:

Network Error
- node_modules\axios\lib\core\createError.js:16:14 in createError
- node_modules\axios\lib\adapters\xhr.js:87:13 in XMLHttpRequest.handleError
- ... 9 more stack frames from framework internals

我不太确定为什么会在node_module本身中发生这种情况。

Axios请求

 // Login - Get User Token
    export const loginUser = (userData) => (dispatch) => {
        axios
            .post('/api/user/login', userData)
            .then((res) => {
                ....
            })
            .catch((err) => {
                console.log(err); <--- Hit's catch
                dispatch({
                    type: 'GET_ERRORS',
                    payload: err.response.data
                });
            });
    };

0 个答案:

没有答案
相关问题