bgfield

Can I use the "try" functionality when adding layers?

Discussion created by bgfield on Apr 3, 2014
Latest reply on Apr 3, 2014 by kenbuja
I've got a map that's adding multiple layers, most of which are on our own server but some which are being hosted on another organization's server.  Over the past week the server from one of the other organizations whose layers we're using has gone down twice, which ends up breaking some the functionality on the map.  I'm hoping there's some way I can use "try" to attempt to add the layer, but skip it if it doesn't appear to be working.  This is what I tried:

  //layerList is an array of DynamicMapServices
  for(i=0;i<layerList.length;i++) {
   try {
    map.addLayer(layerList[i]);
   } catch(err) {
    console.log(err.message);
   }
  }


Unfortunately when I attempt this, I get the same result as if I simply tried to add all the layers at once without "try".  In the console, after about 20-30 seconds, I get the following error message:

""NetworkError: 504 Gateway Timeout - http://(URL for service that's down)"

I haven't worked with try/catch much in the past so I'm sure there's something I'm doing wrong.  Anybody have some advice?

Outcomes