Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't fetch API Resource

Tags:

react-native

I have a react-native application which I'm hooking up to an existing API which already has two clients (webapp, chrome extension). For some reason I just get the generic [TypeError: Network request failed] with nothing more.

The requests that are failing are just basic get requests such as fetch('https://api.mydomain.com/pages/') or axios.get('https://api.mydomain.com/pages/') and they work fine from the webapp and chrome extension that are using this API as well - the requests only fail from the react-native application.

Everything I'm finding on google for this is in regards to localhost or SSL Certificate problems, although these are not my issues because I'm trying to pull from a deployed server and also that server has SSL correctly enabled and I'm using the https endpoint.

Some more notes:

  • when I do go against localhost (using the IP Address, not localhost address) I get this same error.
  • I'm getting this error on Android and I haven't touched nor am concerned yet with iOS
  • I get this same error with fetch and axios
  • The request goes through OK with this endpoint https://jsonplaceholder.typicode.com/posts/1 and I get back a response

This last note is the most interesting because I believe that means there is some issue with my server, however my server is not receiving any request... I have opened up CORS for testing purposes but have the same issue, although if that were the issue the server would have received the request and responded with 403.

like image 242
awwester Avatar asked Sep 14 '26 19:09

awwester


1 Answers

This has to do with Android not trusting my SSL certificate. Apparently Android has some additional trust requirements on top of what web browsers require.

I found this through error.request._response via the axios catch block which showed me the error java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

After figuring that out, the root cause ended up being my SSL Certificate uploaded to AWS didn't have the correct intermediate cert which was fine in chrome, but not in android.

like image 176
awwester Avatar answered Sep 17 '26 20:09

awwester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!