javascript - Best practice to handle 'Internet not Available' (Angular, Ionic, Cordova App) -


i know similar questions have been asked before. but, not find satisfactory answer. so, posting this.

i have app, pulls data server using rest api calls. have 4 primary list views / tabs. here few scenarios:

  1. internet available - good. navigate , forth between views , fetch new data on server. fetched data part of cache view ionic provides. good.

  2. internet disconnected. user navigates view. not able use offline / online event cordova / angular provides takes while after disconnection event fire. meanwhile, screen navigation has fired $http calls (on view enter event) server , returns error because internet not available. dont think wise generalize $http errors internet not available (is there way find error because of no internet?). error because of other error on server side. want able navigate generic error page if happens.

  3. internet disconnected, user tries navigate new view. if new view loaded data show data cached when internet available. if no data loaded, show popup saying "please fix internet". on click of ok, navigate view user came from. haven't found solution achieve this. ofcourse, can handle in controller of every view, make generic service or use httpinterceptor can me once views.

any robust solutions on how above scenarios can handled gracefully?

for 2:

for http call, if failed, call 'anotherapi' 'very simple api unlikely fail on server side', if 'anotherapi' fails, it's no internet problem, otherwise can show generic server error page.

to make sure 'anotherapi' works, can place in domain/another physical location or call services available in internet.

for 3:

in case, not retrieve data api directly, in views, retrieve data , display data handled separately. after retrieve data webservices and/or signalr, put data in internal arrays or internal storage or cookie or client side sqlite. display data, retrieve data client side storage.

i have signalr connection (something socket connection) make sure display data possible newest data since last success internet connection available, signalr server tells me if there new data in server.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -