Nativescript - How to handle No Connection


#1

Hello NS forum,
I have a quick question and a problem,
I would like to create NoConnection page when user is not able to connect to Server …
Im using fetchModule, and doing it something like this:

fetchModule.fetch(`${myUrll}auth/ping`)
        .then(function(result) {
            if (result && result.ok) {
                return true;
            } else {
                frameModule.topmost().navigate({
                    moduleName: config.offlinePage,
                    transition: {
                        name: 'slide',
                    },
                });
            }
        })
        .catch(function() {
            frameModule.topmost().navigate({
                    moduleName: 'offlinePage.js',
                    transition: {
                        name: 'slide',
                    },
            });
        });

But I would like to make it global like to Listen for
System.err: java.net.ConnectException: Connection refused
and then to push user to Offline page


#2

You may check the connectivity type on failure to determine whether the device has a active network connection.


#3

Ok I understand but I dont want to check if device has internet connectivity, I want to check if device can recieve response from source ??


#4

@manojdcoder … I’m working with Vue-Nativescript and I’m trying to connect to my local host but I’m getting connection refused, how do I go about this?


#5

When you say localhost, I assume you have a local server running in your machine. Inside Simulator localhost won’t be reachable, hit with your local IP.


#6

I have my local server running and also I’m testing with a physical device ( an android phone)


#7

Still the answer is same, localhost is valid only to your machine not to your network. It has to be accessed via IP only.