Ionic – how to handle when external api server is offline?
In this StackOverflow question I answered how to handle when external API server is offline.
I'm a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.
As you may know, I'm really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I'm currently #3 in the top All time answerers list.
I answered this question by user Rflujowa:
I'm writing a app in ionic. The app relies on external api's. I've made multiple functions to test the connection, to my own server, and my own server handles the api calls. My own server is needed for this because of ip-whitelistening.
All works well, but now i want to disable the application if the result from my own server is false. I make a call to test the connection everytime the app starts.
What is the best way to handle this with angular/ionic?
1 thought i had myself is to redirect to a landingpage, if no connection is available.
Any tips are welcome.
My answer was:
Yes, basically what you planned to do is OK.
So, just after your app loads up, check if the connection is available (you can read more about how to do that in my detailed post How to check network information change with Ionic framework), and if not then you can change the state to some page where it would clearly let the user know that "Currently the link to the server is not working" (or some better notification).
Also, probably you would want to put a refresh button on that page, so that one could click it and the whole availability process would be checked again (basically same as if someone restarted your app).
Hope this helps.
How to handle when external #API server is offline in @ionicframework? https://t.co/FSGt6AoXCQ
— Nikola Brežnjak (@HitmanHR) January 19, 2016
Leave a Comment