From 1f8ca776f8552bb1c7099c096a44a2d1d032b06d Mon Sep 17 00:00:00 2001 From: "Dan \"Ducky\" Little" Date: Thu, 7 Nov 2024 16:14:53 -0600 Subject: [PATCH] Catch common mapbook issues with nicer errors - Allow graceful failure on a bad mapsource name - Give the user more information on the console regarding bad XML in the mapbook. --- src/gm3/application.js | 7 +++++++ src/gm3/reducers/mapSource.js | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/gm3/application.js b/src/gm3/application.js index dde91d41..f243fe40 100644 --- a/src/gm3/application.js +++ b/src/gm3/application.js @@ -348,6 +348,13 @@ class Application { let mapbookXml = contents; if (typeof contents === "string") { mapbookXml = new DOMParser().parseFromString(contents, "text/xml"); + if (mapbookXml.documentElement.nodeName === "parsererror") { + console.error( + "Could not parse mapbook!", + mapbookXml.documentElement.innerHTML + ); + return false; + } } this.configureSelectionLayer( diff --git a/src/gm3/reducers/mapSource.js b/src/gm3/reducers/mapSource.js index 72e0a881..5f907534 100644 --- a/src/gm3/reducers/mapSource.js +++ b/src/gm3/reducers/mapSource.js @@ -82,14 +82,18 @@ const reducer = createReducer( state, { payload: { mapSourceName, layerName, on } } ) => { - state[mapSourceName].layers = modifyLayer( - state[mapSourceName].layers, - layerName, - (layer) => { - layer.on = on; - return layer; - } - ); + if (!state[mapSourceName]) { + console.error("Map source does not exist: ", mapSourceName); + } else { + state[mapSourceName].layers = modifyLayer( + state[mapSourceName].layers, + layerName, + (layer) => { + layer.on = on; + return layer; + } + ); + } }, [favoriteLayer]: ( state, @@ -104,6 +108,8 @@ const reducer = createReducer( return layer; } ); + } else { + console.error("Map source does not exist: ", mapSourceName); } }, [setLayerTemplate]: (