12 days ago
Hi there,
Backend: Django hosted on Railway
Frontend: React native based android app using fetch
Issue? On all the POST APIs, I'm getting "Network Request Failed"
I understand the error is vague, so I did some debugging on my side..
- No frontend code was pushed recently.
- No backend code was pushed.
I have been facing it for the last 1-2 weeks.
In my debugging, nothing from the code side seems like an issue.. The same API is working fine from Postman.
Even in my logs.. I can see the backend is returning 200 OK, but the frontend shows Network Request Failed.
I've also tried adding Connection: Close to my API Headers, and surprisingly it works half the time.
Moreover, my GET requests are working just fine.. its just my POST APIs which are failing. And it's a big issue, since users can't even create their profile.
I have also tried using the Railway-based host.. .....up.railway.app, and the result is same which means issue is not from Cloudflare side.
15 Replies
12 days ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • 12 days ago
mayori
Does your POST requests appear in the Network Logs?
12 days ago
Yes, they do. They are responding with 200 OK, and I am saving data correctly in the database. So, in my opinion, the backend is working fine.
Yes, they do. They are responding with `200 OK`, and I am saving data correctly in the database. So, in my opinion, the backend is working fine.
12 days ago
basically what re u using the fetch for have you already build the apk
try to check if ur frontend if u set up any api or using context share here how the fetch request is
Yes, they do. They are responding with `200 OK`, and I am saving data correctly in the database. So, in my opinion, the backend is working fine.
12 days ago
the problem is not the backend the problem is in ur react native
manuproject
basically what re u using the fetch for have you already build the apk try to check if ur frontend if u set up any api or using context share here how the fetch request is
12 days ago
Yes, the APK is already built and has been live for months without any issue.
I actually debugged the whole APK - nothing was changed in the last 2 weeks.. since the issue started appearing.. I also checked the entire logs on my APK; except for "Network request failed" I see nothing. No crashes. No errors. Just "Network request failed"
12 days ago
did u debug using the web version of react native or how cos with that u can really find the exact error
by using the chrome dev tools
Yes, the APK is already built and has been live for months without any issue. I actually debugged the whole APK - nothing was changed in the last 2 weeks.. since the issue started appearing.. I also checked the entire logs on my APK; except for "Network request failed" I see nothing. No crashes. No errors. Just "Network request failed"
12 days ago
or tell me how you debug let me understand very well
manuproject
or tell me how you debug let me understand very well
12 days ago
It's not supported on the browser because of certain libraries I use.
I did LOGCAT over the traces; I only see this
I ReactNativeJS: 'FULL ERROR:', '{"message":"Network request failed"}'
That too is just the console I am doing in my local.
I also did Connection: Close forcing the APK to terminate the network, which does help. The first request fails.. but then since the connection is terminated.. my second API is a success. But this is, of course, not a sustainable solution, and that's a reason I'm doubting the infra level instead of just the frontend code. (Frontend Infra can also be an issue - how services are interacting)
It's not supported on the browser because of certain libraries I use. I did LOGCAT over the traces; I only see this `I ReactNativeJS: 'FULL ERROR:', '{"message":"Network request failed"}'` That too is just the console I am doing in my local. I also did `Connection: Close` forcing the APK to terminate the network, which does help. The first request fails.. but then since the connection is terminated.. my second API is a success. But this is, of course, not a sustainable solution, and that's a reason I'm doubting the infra level instead of just the frontend code. (Frontend Infra can also be an issue - how services are interacting)
12 days ago
re u using expo with react native??
12 days ago
It's marked as resolved, which isn't the case, unfortunately. Is there any way we can ping/open it again?
12 days ago
Thanks for a detailed response.
Strangely, I only see this in logs, after doing the changes as you posted.. and I'm still getting "Network Request Failed"
08-09 20:52:21.471 14471 15046 D NET : POST proto=h2
08-09 20:52:32.559 14471 15046 D NET : POST proto=h2
08-09 20:52:50.780 17090 17467 D NET : POST proto=http/1.1
08-09 20:52:51.389 17090 17468 D NET : POST proto=h2
08-09 20:52:51.391 17090 17469 D NET : GET proto=h2
08-09 20:52:51.458 17090 17467 D NET : GET proto=h2
08-09 20:52:52.772 17090 17467 D NET : GET proto=h2
08-09 20:52:52.774 17090 17468 D NET : GET proto=h2
08-09 20:52:52.785 17090 17469 D NET : GET proto=h2
08-09 20:53:16.051 17090 17468 D NET : GET proto=h2
08-09 20:53:24.604 17090 17468 D NET : POST proto=h2
08-09 20:53:27.186 17090 17468 D NET : POST proto=h2
08-09 20:53:28.335 17090 17468 D NET : POST proto=h2
12 days ago
I still have to test forcing the HTTP.. I will do in a while and update.
POST API is pretty simple: a simple JSON. The one I'm testing on has <10ms latency.,
12 days ago
Hey, so I tested all three cases, and they all worked perfectly!
Now my doubt is about the HTTP/2's connection pool in some way. Possibly the connection ended, but the App is not aware of it somehow. Is that the reason using Connection: Close was working? Forcing the app to terminate the port and build a fresh one for the next request?
12 days ago
Hmm, fair. But aren't we treating the symptoms instead of figuring/fixing the root cause?
For now, since the Backend is working fine and receiving the API, the profile does get created; my user sees "Network Request Failed", they close the app, and open it again - which is a very high friction point and a significant drop-off. So it might work as a temporary fix. But what's the underlying main issue? I'm sure this isn't the first or the last issue..
12 days ago
I really appreciate your responses and knowledge. Means a lot - I had to study a bit to understand things here and there. Thanks for that too. Appreciate your help.
