{"id":2509,"date":"2016-01-19T07:18:23","date_gmt":"2016-01-19T07:18:23","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=2509"},"modified":"2016-01-19T07:22:42","modified_gmt":"2016-01-19T07:22:42","slug":"ionic-how-to-handle-when-external-api-server-is-offline","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/ionic-how-to-handle-when-external-api-server-is-offline\/","title":{"rendered":"Ionic &#8211; how to handle when external api server is offline?"},"content":{"rendered":"<p>In this StackOverflow question I answered how to handle when external\u00a0API server is offline.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[2509]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>As you may know, I&#8217;m really into Ionic framework lately\u00a0and am helping out on StackOverflow with the knowledge I gained so far with the framework. I&#8217;m currently <strong>#3<\/strong> in the <a href=\"http:\/\/stackoverflow.com\/tags\/ionic\/topusers\">top All time answerers<\/a> list.<\/p>\n<p>I answered <a href=\"http:\/\/stackoverflow.com\/questions\/33982976\/ionic-how-to-handle-when-external-server-is-offline\/33986874\">this question<\/a>\u00a0by user <a href=\"http:\/\/stackoverflow.com\/users\/4174909\/rflujowa\">Rflujowa<\/a>:<\/p>\n<p>I&#8217;m writing a app in ionic. The app relies on external api&#8217;s. I&#8217;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.<\/p>\n<p>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.<\/p>\n<p>What is the best way to handle this with angular\/ionic?<\/p>\n<p>1 thought i had myself is to redirect to a landingpage, if no connection is available.<\/p>\n<p>Any tips are welcome.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/33982976\/ionic-how-to-handle-when-external-server-is-offline\/33986874#33986874\">My answer<\/a> was:<\/p>\n<blockquote><p>Yes, basically what you planned to do is OK.<\/p>\n<p>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 <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/codeproject\/check-network-information-change-with-ionic-famework\/\" rel=\"nofollow\">How to check network information change with Ionic framework<\/a>), and if not then you can change the state to some page where it would clearly let the user know that &#8220;Currently the link to the server is not working&#8221; (or some better notification).<\/p>\n<p>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).<\/p>\n<p>Hope this helps.<\/p><\/blockquote>\n<blockquote class=\"twitter-tweet\" data-width=\"550\">\n<p lang=\"en\" dir=\"ltr\">How to handle when external <a href=\"https:\/\/twitter.com\/hashtag\/API?src=hash\">#API<\/a> server is offline in <a href=\"https:\/\/twitter.com\/Ionicframework\">@ionicframework<\/a>? <a href=\"https:\/\/t.co\/FSGt6AoXCQ\">https:\/\/t.co\/FSGt6AoXCQ<\/a><\/p>\n<p>&mdash; Nikola Bre\u017enjak (@HitmanHR) <a href=\"https:\/\/twitter.com\/HitmanHR\/status\/689346774054612992\">January 19, 2016<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this StackOverflow question I answered how to handle when external\u00a0API server is offline. I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1991,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,35],"tags":[],"class_list":["post-2509","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ionic","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=2509"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2509\/revisions"}],"predecessor-version":[{"id":2512,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2509\/revisions\/2512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/1991"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=2509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=2509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=2509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}