Esri/react-arcgis

How to trap errors during webmap load

Closed this issue · 1 comments

slead commented

If the webmap contains a layer which is broken, the entire application fails with The ArcGIS API failed to load. Another way to reproduce this error is by providing a non-existing webmap ID.

Expected behavior

  1. Can we display the actual error message returned by the API (Item does not exist or is inaccessible) , rather than the generic message The ArcGIS API failed to load?
  2. Possibly more difficult, when a single layer fails could the webmap load with that layer omitted, rather than failing completely? (This may be an issue for the JS API in general rather than react-arcgis)

Screen Shot 2020-11-27 at 12 39 42 pm

Actual behavior
The react-arcgis WebMap fails completely with the aforementioned message "The ArcGIS API failed to load".

To Reproduce
See the simple demo at https://codesandbox.io/s/broken-webmap-0tzc4?file=/src/index.js which contains a link to a non-existent webmap ID.

Versions (please complete the following information):

  • react-arcgis version 5.1.0
  • esri-loader version ^2.16.0
  • ArcGIS API for JavaScript version 4.17
slead commented

I think this can be solved with an onFail handler:

const handleFail = function(e){
  console.error("There was an error loading the map", e.message);
}

<WebMap
      onLoad={handleMapLoad}
      onFail={handleFail}