axios icon indicating copy to clipboard operation
axios copied to clipboard

Network Error in React Native

Open nkqdev opened this issue 1 year ago • 18 comments

Describe the bug

When i'm POSTa request then in the processing i'm switch to another app (before i'm receive response from server) then when i'm come back it say Network Error is anyone have the same issue and know the way to deal with this problem?

To Reproduce

No response

Code snippet

No response

Expected behavior

No response

Axios Version

^1.6.2

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

iOS 16.4

Additional Library Versions

RN 0.71.8
React 18.2.0

Additional context/Screenshots

No response

nkqdev avatar Mar 15 '24 09:03 nkqdev

I'm getting the same error, but only from Android. I don't think this is related to Axios because I used the bare JavaScript fetch method and the API call just never resolves.

kurucaner avatar Mar 15 '24 12:03 kurucaner

I'm getting the same error, but only from Android. I don't think this is related to Axios because I used the bare JavaScript fetch method and the API call just never resolves.

I'm stuck at this problem for like 1 week. Some people say that axios isn't using an API that called NSURLSession provide by Apple to make a request so when user switch to another app the OS just cancel that request.

nkqdev avatar Mar 16 '24 01:03 nkqdev

I'm getting the same error, but only from Android. I don't think this is related to Axios because I used the bare JavaScript fetch method and the API call just never resolves.

I'm stuck at this problem for like 1 week. Some people say that axios isn't using an API that called NSURLSession provide by Apple to make a request so when user switch to another app the OS just cancel that request.

Honestly, in my case, I'm convinced that this is a backend problem. I created a basic Node.js backend and made a similar API call to it; everything was working just fine. We are looking into the issue and will keep you updated if we figure this out.

kurucaner avatar Mar 17 '24 16:03 kurucaner

@nkqdev If it's GET data, if fetch data error, it should have chance to retry few times. check this article 3 Tips to Make Your App More Stable

@kurucaner And the android error, I think it's because you use '127.0.0.1' or 'localhost', I met this error before, and change the local IP to LAN ip(for example, like 192.168.1.10), then it's worked.

I use expo and this is how I get LAN ip in dev mode:

import Constants from 'expo-constants';

const host = Constants.expoGoConfig?.debuggerHost?.split(':')?.[0];
const API_URL = process.env.EXPO_PUBLIC_API_URL || '';

export const baseURL =
  host &&
  (host.startsWith('192.168') || host.startsWith('10.') || host.startsWith('172.')) &&
  (API_URL.indexOf('localhost') > -1 || API_URL.indexOf('127.0.0.1') > -1)
    ? 'http://' + host + ':' + (API_URL.split(':').pop() || '')
    : API_URL;

suhaotian avatar Mar 24 '24 03:03 suhaotian

@suhaotian I'm using SOAP service so when it's say Network Error everything just stop and i don't see any retry

nkqdev avatar Mar 25 '24 04:03 nkqdev

same issue ,any resolution?

vivek0046 avatar Apr 05 '24 05:04 vivek0046

Em facing the same issue ....!

MenamAfzal avatar Apr 06 '24 07:04 MenamAfzal

Em facing the same issue ....!

wilsonmjunior avatar Apr 10 '24 18:04 wilsonmjunior

Facing the same problem, any solution?

isaiasnovais avatar Aug 09 '24 14:08 isaiasnovais

Guys I found solution. Its not axios problem. You need add certificates into your network_security_config image

Also add android:usesCleartextTraffic="true"

Also add xml folder into your res/ and paste this code:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="@raw/ca" />
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

After that you need add your certificates into res/raw/NAME_OF_CERT

That's all!

TimeForRelax avatar Aug 23 '24 09:08 TimeForRelax

@nkqdev @kurucaner @MenamAfzal @vivek0046

TimeForRelax avatar Aug 23 '24 14:08 TimeForRelax

@TimeForRelax how can i get the certificates?

carlgrob5171989 avatar Aug 28 '24 15:08 carlgrob5171989

Trying this..

On Wed, Aug 28, 2024 at 8:56 PM Full Stack Developer < @.***> wrote:

@TimeForRelax https://github.com/TimeForRelax how can i get the certification?

— Reply to this email directly, view it on GitHub https://github.com/axios/axios/issues/6302#issuecomment-2315671219, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASQEV3G67RCLUUCFXQKWPMLZTXT3BAVCNFSM6AAAAABEXUUFBOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJVGY3TCMRRHE . You are receiving this because you were mentioned.Message ID: @.***>

-- Vivek Rana

Founder

3Sigma Sales platform +91 8814048362 <+91+8814048362> @.*** www.3sigmacrm.com Magnum towers, Sector 58, Gurgaon [image: facebook] https://facebook.com/3sigma [image: twitter] https://twitter.com/3sigmacrm [image: linkedin] https://www.linkedin.com/company/71206402

https://www.hubspot.com/email-signature-generator?utm_source=create-signature

vivek0046 avatar Aug 28 '24 16:08 vivek0046

certificates

You need ask your backend guys

TimeForRelax avatar Aug 29 '24 06:08 TimeForRelax

@TimeForRelax thanks for your information I will try it

nkqdev avatar Aug 29 '24 06:08 nkqdev

Get an ssl certificate from aws. I think it's free of cost

On Thu, 29 Aug 2024, 12:22 nkqdev, @.***> wrote:

@TimeForRelax https://github.com/TimeForRelax thanks for your information I will try it

— Reply to this email directly, view it on GitHub https://github.com/axios/axios/issues/6302#issuecomment-2316842601, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASQEV3GSI5EYOHIBZCYFUMDZT3AKFAVCNFSM6AAAAABEXUUFBOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJWHA2DENRQGE . You are receiving this because you were mentioned.Message ID: @.***>

vivek0046 avatar Aug 29 '24 07:08 vivek0046