Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeError: Network request failed] either with fetch API or axios on android #29698

Closed
EshgheCode opened this issue Aug 19, 2020 · 24 comments
Closed
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@EshgheCode
Copy link

I have a problem with fetching an API on my code I use both fetch and axios but the result is same:
[type error: Network request failed]

here is my code for fetch:
useEffect(() => { fetch('https://jsonplaceholder.typicode.com/users') .then((res) => res.json()) .then((data) => { console.log(data) }) .catch((err) => console.log(err)) }, []);

I don't use an emulator because my CPU doesn't support vt-x. so I use a Xperia TX which has android 4.3 and I connect it over Wi-Fi to see my result. it work properly so far but the only problem is this API fetching.

React Native version:

0.63.2

@react-native-bot react-native-bot added Platform: Android Android applications. Platform: iOS iOS applications. 🌐Networking Related to a networking API. labels Aug 19, 2020
@arasrezaei
Copy link

same here, those api's are so unstable on android:
i have another similar problem with them:
#29267

@EshgheCode
Copy link
Author

same here, those api's are so unstable on android:
i have another similar problem with them:
#29267

I saw your issue. and I try to use my code on snack, and it worked properly :

https://snack.expo.io/aXH9PxyIS

I just wonder why it doesn't work on a real device.
isn't that because of my Android version which is quite old?

@ambarc
Copy link

ambarc commented Aug 27, 2020

Related. Try adding headers and see if that fixes?

@3zvan
Copy link

3zvan commented Sep 8, 2020

Try this maybe? I had a similar error, had connection but all fetch and axios calls returned an error (and sometimes straight crash depending on the endpoint) but the linked solution worked for me.

@stale
Copy link

stale bot commented Dec 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@gvsakhil
Copy link

gvsakhil commented Jan 31, 2021

Still I have this issue. Sometimes my https api works and sometimes it throws [TypeError: Network request failed]

IOS is working fine but not android

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 31, 2021
@SohaibKtb
Copy link

Still I have this issue. Sometimes my https api works and sometimes it throws [TypeError: Network request failed]

IOS is working fine but not android

me too

1 similar comment
@akeuk
Copy link

akeuk commented Mar 25, 2021

Still I have this issue. Sometimes my https api works and sometimes it throws [TypeError: Network request failed]

IOS is working fine but not android

me too

@gvsakhil
Copy link

Hi @SohaibKtb @akeuk The issue got resolved for me after correctly installing the SSL Certificate.

@pallaviMN
Copy link

@gvsakhil , can u please let me know the steps to install SSL certificate in Android & iOS?

@geovrisco
Copy link

Hi @SohaibKtb @akeuk The issue got resolved for me after correctly installing the SSL Certificate.

how? i have same problems

@raffaeler
Copy link

Same issue here, but the TLS certificates are correctly installed:

  • chrome shows a valid chain accessing the same webapi
  • other apps doing the same request are successful

@hoaxvo16
Copy link

hoaxvo16 commented Feb 24, 2022

You can try my solution

#24627 (comment)

Same issue here, but the TLS certificates are correctly installed:

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 29, 2023
@raffaeler
Copy link

The TypeError: Network request failed is a generic and useless error used for tons of reasons.
The most probable solution is here: #32931

In any case, throwing a generic error is a bug without any doubt. And it should be fixed.

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 30, 2023
@JKKholmatov
Copy link

fetch("https://jsonplaceholder.typicode.com/todos/1") request sometimes hangs for 2 minutes, cannot find any solution

@raffaeler
Copy link

fetch("https://jsonplaceholder.typicode.com/todos/1") request sometimes hangs for 2 minutes, cannot find any solution

The fetch API is asynchronous.
If it is blocking, it depends on your code.
If it takes a long time (regardless your code is blocking) it depends on some wrong parameters/URL or connection issues or server side issues.

In any case the react-native api does not provide a detailed error information, which is the point of this open issue.

@JKKholmatov
Copy link

JKKholmatov commented Aug 28, 2023

fetch("https://jsonplaceholder.typicode.com/todos/1") request sometimes hangs for 2 minutes, cannot find any solution

The fetch API is asynchronous. If it is blocking, it depends on your code. If it takes a long time (regardless your code is blocking) it depends on some wrong parameters/URL or connection issues or server side issues.

In any case the react-native api does not provide a detailed error information, which is the point of this open issue.

I created a new Expo project, added only one fetch button and tested, with iOS it works without any issue, hang is occuring on Android, when I leave the phone for 5 minutes and then call function it defenitely waits always ~2 minutes to send request and get response, I am looking for soluftion for a week but cannot find any solution,

@raffaeler
Copy link

I created a new Expo project, added only one fetch button and tested, with iOS it works without any issue, hang is occuring on Android, when I leave the phone for 5 minutes and then call function it defenitely waits always ~2 minutes to send request and get response, I am looking for soluftion for a week but cannot find any solution,

This is not very relevant.

  • You should assume that fetch works well on every platform as it is the most used API.
  • If it hangs, it means you wrote code that is waiting synchronously (which is wrong)
  • This is not the right place as the issue title deals with a different problem.

My suggestion:

  • start with the exact code of an official tutorial
  • if you feel there is something wrong, open a new issue as you (we) are OT here

@JKKholmatov
Copy link

I created a new Expo project, added only one fetch button and tested, with iOS it works without any issue, hang is occuring on Android, when I leave the phone for 5 minutes and then call function it defenitely waits always ~2 minutes to send request and get response, I am looking for soluftion for a week but cannot find any solution,

This is not very relevant.

  • You should assume that fetch works well on every platform as it is the most used API.
  • If it hangs, it means you wrote code that is waiting synchronously (which is wrong)
  • This is not the right place as the issue title deals with a different problem.

My suggestion:

  • start with the exact code of an official tutorial
  • if you feel there is something wrong, open a new issue as you (we) are OT here

I got it, thank you, I opened a new issue and looking for a help from admins!

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 26, 2024
Copy link

github-actions bot commented Mar 4, 2024

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Mar 4, 2024
@raffaeler
Copy link

with no activity.

... "with no fix" would better represent the general problem

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests