Skip to content

Commit

Permalink
Catch common mapbook issues with nicer errors
Browse files Browse the repository at this point in the history
- Allow graceful failure on a bad mapsource name
- Give the user more information on the console regarding bad XML in
  the mapbook.
  • Loading branch information
theduckylittle committed Nov 7, 2024
1 parent 1912bfd commit 1f8ca77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/gm3/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 14 additions & 8 deletions src/gm3/reducers/mapSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -104,6 +108,8 @@ const reducer = createReducer(
return layer;
}
);
} else {
console.error("Map source does not exist: ", mapSourceName);
}
},
[setLayerTemplate]: (
Expand Down

0 comments on commit 1f8ca77

Please sign in to comment.