1

Hello guys,

I'm working on an app based on Ionic - so AngularJS. In my testing of the app I connected my device to a very slow wifi, to test how the app responds... It's awful, but not too bad because the problem is very localised.

At first the app wouldn't load at all. Channel not fired: onDOMContentLoaded appears in the console, and an alert shows Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html).

I followed the tip here : increase loadUrlTimeoutValue

The app stopped crashing. BUT it would remain on a white screen, until eventually the only http call in the index.html fails :

http://maps.googleapis.com/maps/api/js?key=myKey&libraries=places

The console logs Failed to load resource: net::ERR_TIMED_OUT and the app bootstraps like usual. Second thing, the images that has to be displayed in the gallery of the app won't show up, getting me a bunch of 408 (Request Time-out) after a long load time, for example

GET http://res.cloudinary.com/myimage.jpg 408 (Request Time-out)

So my guess is, on this very slow wifi, all http calls are an issue - they simply fail after some time and returns an error that the console is able to display.

My simple question : how to catch that type of error globally to be able to display a message to the user ? Or even better, listen to any http call and timeout myself after 5s or so to display the said message ?

Thanks ahead !

Community
  • 1
  • 1
Jeremy Belolo
  • 3,891
  • 5
  • 39
  • 79

1 Answers1

0

Angulars $http service has a timeout property in config argument. You can set it to 5s (5000 as it is in miliseconds). Then you can handle timeout in error callback.

apieceofbart
  • 1,826
  • 4
  • 20
  • 29
  • Thanks for answering. I know about this, but it won't help, really, since I'm not invoking anywhere the $http service. As I said, it's a script tag calling the maps api, and img tags with their url argument. – Jeremy Belolo Jun 02 '16 at 15:35
  • Not an issue of Angular, no, but a way to handle this globally is not something theorically strange - maybe a global config to set or something I didn't hear about yet... Anyway, a regular Javascript way could potentially lead to a solution as well. – Jeremy Belolo Jun 04 '16 at 19:09