We're using axios to make requests from our react-native app.
Today we bumped onto an issue where an old Samsung device couldn't reach our servers, and it was because our servers no longer support old TLS. The customer tried reaching our servers through the an old Samsung browser the device had, and couldn't. After they installed Chrome they were able to reach our servers without issues.
If axios returned a more specific error, we'd have probably figured out what went wrong, but instead axios returned a generic 'Network Error'.
All I'm now asking is this, is there a way to make axios more verbose when it comes to errors, or more specific?
p.s I'm still not sure how to resolve the tsl issue itself either.
As far as I know axios on background uses two types of request structure. HTTP and XHR. Since react-native does not run on node engine it is probably using XHR and the error you are seeing is related to this line.
// Handle low level network errors
request.onerror = function handleError() {
// Real errors are hidden from us by the browser
// onerror should only fire if it's a network error
reject(createError('Network Error', config, null, request));
// Clean up request
request = null;
};
Although this is not exactly an answer to your question, might give you a start point.
Related
I am working on an ionic 3 Project. When i run the project on android i get the following error.
Access to XMLHttpRequest at 'https://baseurl.com/api' from origin 'file://' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://baseurl.com' that is not equal to the supplied origin.
I started getting this error from last week monday and until then it was working fine.
In the requests(POST/GET) i am using the following headers
headers.append('Content-Type', 'application/x-www-form-urlencoded');
or
headers.append('Content-Type', 'application/json');
According to the ionic documentation CORS Errors, what i understood was that there are changes has to be done from the server side. Is there anything can be done from the ionic side? What could be the issue?
Two problems with your issue. One is more simple, and one is that https://baseurl/api doesn’t have a .com, or a .anything, so it is mostly invalid. The second that CORS is a necessary evil to deal with. You are going to have to set up a local server do deal with it, as some requests cannot be made by items being served by a file:// protocol. Local servers can be set up a variety of ways, depending on your situation. It would be helpful to explain how you are running it, and what tools you are using, so that we may be able to better help you.
The issue is due to a chrome update and for further details about the issue please refer This.
Update the 'Android System Webview' in google play store to the latest version and this issue will go away
I have an ionic app that when I run that on iOS then it works perfectly fine but when I run that on Android I get this error
Http failure response for (unknown url): 0 Unknown Error
Any reason I am getting this one? I have allowed CORS on server side as it is working on iOS devices.
Any help?
EDIT
This is what I have in my app.js file
const cors = require('cors');
And then I simply use it with default options.
app.use(cors());
If you are using localhost, change it to the IP address of the localhost. Android doesn't seems to support it where iOS do.
Try actual host name in case it didn't work too.
First you dont need CORS to call API from your android device.
Second probably your server is not accepting your request. If you are using Cloud then your server must accept request from any IP. There must be a option for allow IP address, place there from 0.0.0.1 to 254.254.254.254 so that each and every user can call your API.
Third you need to allow origin from your config.xml and also in header for CROS request. Check your API header and config file.
And fourth If your service is running under http then it will also could be the problem. Secure your service by adding SSL certificate. This could fix your problem.
We had experienced the same Error several times in our App. In our case it was a problem with the headers of the request and also a CORS problem on the serverside.
Are you able to reproduce this error in the browser if you emulate a android device? Then you could compare them with the headers of the iOS request.
Or you can try to log the incoming requests on the server-side to see if the requests reach the server and what headers are set.
Hope my ideas help :)
The solution is to add NODE_TLS_REJECT_UNAUTHORIZED=0 to your environment to disable the SSL verification in Node.js.
Note : You should only set this in development, Don't do this in production
EDIT
In that case it indicates that CORS has not been properly setup on your server. Go through the issue here
I have an react native app that talks to my Node server running on my laptop(http://192.168.x.x:3000). Even after performing an successful login, the consequent calls to my server fails with an 401 status. I see that no cookies are passed on the server.
Some observations:
1) My React Native app works just fine when i deploy my code to an actual server and use a proper domain(http://example.com) while making the API calls.
2) Using postman, I am able to authenticate myself and make consequent successful API calls to my local server.
This is a really strange issue and am sure I have missed out something small, but have been stuck with it for quite some time now.
Any hints/suggestions on what can be done?
Thanks,
I recognize this is a little old, but if anyone is still facing issues, I found that the following steps resolved it for me
Include withCredentials on all requests from the react app
Used the cors middleware server side. Be sure to specify the domain (in my case, my VM's IP address with port) and set credentials to true
Increase the maxAge property -- I think the default was like 10 seconds so it kept seeming like my session wasn't persisting when in reality it was just expiring too fast.
An example for steps 2 and 3 might look something like:
const express = require('express');
const path = require('path');
const session = require('express-session');
const cors = require('cors')
const app = express();
// STEP 2
app.use(cors({
credentials: true,
origin: '192.168.0.100:3000',
methods:['GET', 'POST', 'PUT', 'DELETE']
}));
// STEP 3
app.use(session({
cookie: {
maxAge: 86400000 // one day
}
}));
EDIT:
Also worth mentioning that if you're running your server on a virtual machine (like me) to be sure your virtual machine's date is consistent with the date of the device running your react app. I discovered the hard way that this also manifests as Axios appearing to lose sessions.
Fetch is throwing a Network request failed error when I try to make a request to a local server in the Android emulator. I'm pretty sure the request isn't getting out of the app.
I've checked and double checked the request headers and target URL, all correct (Hitting the right URL and specifying Content-Type and Accept). I tried disabling CORS on my local server, no effect.
I'm using digits in my app and digits is able to make contact with its server outside the app and return authorization, so I'm think something is going on with React-Native.
I've tried manipulating the app permissions, but no dice, it only needs the android.permissions.INTERNET heading in the manifest.
Any ideas on how to move forward, either a quick fix or something I've overlooked?
Figured it out, the problem was that the android emulator runs in a VM. I was trying to hit localhost, which was pointing at the VM, so I needed to specify my ip or 10.0.2.2 instead.
I am re-implementing an existing worklight system. We have already have a hybrid version. We have decided to re-implement the Client side in pure native. The native client seems work fine.
However, the server seems to be quite unstable - sometimes we don't get a server response after invoking an adapter, sometimes we do get. I have checked the DDMS/Android console. And a Error/Exception was found. Any comments would be appreciated!
com.worklight.common.Logger$SendLogsRequestListener(4274): Logger$SendLogsRequestListener.onFailure in Logger.java:1726 :: Failed to POST data from file /data/data/${APP_NAME}/files/analytics.log.0.send due to: HTTP response code: 500
On a successful adapter call or WLClient connection to the server, the client will attempt to automatically send logs to the server. It looks like something bad is happening on the autosend for adapters. A temporary workaround would be to disable this auto sending behavior by calling
WL.Logger.setAutoSendLogs(false)
But you can only use this call if you do not wish for logs to be sent automatically. If you do wish to have this working properly, I'd suggest opening a PMR so that it can be determined if this is an error in your application or an actual defect.