Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 反应本机Axios无法';从网络请求捕获错误失败_Android_React Native_Axios - Fatal编程技术网

Android 反应本机Axios无法';从网络请求捕获错误失败

Android 反应本机Axios无法';从网络请求捕获错误失败,android,react-native,axios,Android,React Native,Axios,因此,我有一个函数在登录我的react本机应用程序时调用我的API。不知何故,现在当我尝试调用API时,服务器出现了一个错误:connect-econnreference103.129.220.210:443 我认为应该在我的try-catch块程序或.then-and.catch块程序中捕获此错误。然而,它只是在我的日志中弹出警告,并没有进入我的捕获块或任何东西。这是我的登录功能代码: logIn: (email, password) => { dispatch({typ

因此,我有一个函数在登录我的react本机应用程序时调用我的API。不知何故,现在当我尝试调用API时,服务器出现了一个错误:
connect-econnreference103.129.220.210:443

我认为应该在我的try-catch块程序或.then-and.catch块程序中捕获此错误。然而,它只是在我的日志中弹出警告,并没有进入我的捕获块或任何东西。这是我的登录功能代码:

logIn: (email, password) => {
        dispatch({type: 'LOADING'})
        try {
          console.log("API call in login function")
          axios.post('https://dev.akademis.id/api/user/login', {
            "email": email,
            "password": password
          })
            .then(async res => {
              const userToken = String(res.data.data.id)
              if (res.data.data.ptn && res.data.data.jurusan) dispatch({type: 'PROFILE SET'})

              try {
                await AsyncStorage.setItem('userToken', userToken)
                await AsyncStorage.setItem('userPass', password)
              } catch (e) {
                console.log("Error dari async storage: ")
                console.error(e)
                dispatch({type: 'STOP LOADING'})

                throw e
              }

              dispatch({type: 'LOGIN', token: userToken, password: password})
            })
            .catch(err => {
              Alert.alert("Error", err.response.data.message)
              console.log(err.response.data.message)
              dispatch({type: 'STOP LOADING'})

              throw(err)
              // Email & pass required, using @, and ., pass minimum 8 chars
            })
        } catch (e) {
          Alert.alert("Server dalam maintainance", "Kami meminta maaf atas ketidaknyamanan ini")
          console.log(e.response)
          dispatch({type: 'STOP LOADING'})
        }
      }
以下是我在日志中的错误:

API call in login function
[Tue Sep 29 2020 08:52:54.884]  WARN     Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26065:33
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30563:17
callTimers@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30771:19
__callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2776:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2508:31
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2730:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2507:21
callFunctionReturnFlushedQueue@[native code]
``

你在用哪个图书馆?或者?我正在使用react-native axiosTry-react-native axios不是最新版本,上一次发布是在4年前。我也遇到了同样的问题,切换到npmjs.com/package/axios解决了这个问题您使用的是哪个库?或者?我正在使用react-native axiosTry-react-native axios不是最新版本,上一次发布是在4年前。我也遇到了同样的问题,切换到npmjs.com/package/axios解决了这个问题