Axios request getting cancelled in android
-
I build an application in quasar, which is working fine in browser. But, my android debug app it’s not working. The app has a login form, in the very 1st step. The api call is not working as the request is getting cancelled. I have connected my device using chrome remote device option, and it’s saying request cancelled. Any suggestion will be helpful, as it’s my 1st mobile app.
-
Is the request to a backend server somewhere on the internet?
Are you making the correct call (GET, PUT, POST, etc) for the receiving api?
With mobile, is this reqired to be https?
I don’t do mobile, so don’t know. Just throwing some things out. -
Hi @Hawkeye64, It’s requesting to a live server with a valid SSL certificate. Also, I have implemented correct methods(GET, PUT, POST etc.). The app is working perfectly when I am testing it from any web browser, there must be something wrong in the mobile part.
-
Finally I was able to find out the issue, the request was failing due to some issue in Axios interceptor, which occurring only in android
-
@technowebs Ouch! I use axios interceptors too. Very convenient, but can also give you a lot of grief trying to track it down if there’s an issue in one.
-
@Hawkeye64 Here is the code I have written in the interceptors,
axios.interceptors.request.use(function(config) { // Get the token from session storage var token = SessionStorage.getItem('token'); // Check valid token if (token === null) { let publicPath = ['#/login', '#/forget-password']; // Redirect to Login if login required if (publicPath.indexOf(window.location.hash) === -1) { window.location.href = '/#/login' } } else { // Set token token = JSON.parse(token) if (token) { config.headers.Authorization = 'Bearer ' + token } } return config; });
The problem was occurring due to the property window.location.hash, which is returning different values in mobile(now checking with android only).