Add better error handling, fixes #452

This commit is contained in:
pietervdvn 2021-09-22 17:29:50 +02:00
parent 73f76881c4
commit e18eb06f14

View file

@ -39,6 +39,8 @@ import LayoutConfig from "./Models/ThemeConfig/LayoutConfig";
import LayerConfig from "./Models/ThemeConfig/LayerConfig";
import Minimap from "./UI/Base/Minimap";
import Constants from "./Models/Constants";
import Combine from "./UI/Base/Combine";
import {SubtleButton} from "./UI/Base/SubtleButton";
export class InitUiElements {
static InitAll(
@ -209,8 +211,8 @@ export class InitUiElements {
static LoadLayoutFromHash(
userLayoutParam: UIEventSource<string>
): [LayoutConfig, string] {
try {
let hash = location.hash.substr(1);
try {
const layoutFromBase64 = userLayoutParam.data;
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
@ -249,9 +251,21 @@ export class InitUiElements {
userLayoutParam.setData(layoutToUse.id);
return [layoutToUse, btoa(Utils.MinifyJSON(JSON.stringify(json)))];
} catch (e) {
new FixedUiElement(
"Error: could not parse the custom layout:<br/> " + e
).AttachTo("centermessage");
if(hash === undefined || hash.length < 10){
e = "Did you effectively add a theme? It seems no data could be found."
}
new Combine([
"Error: could not parse the custom layout:",
e,
new SubtleButton("./assets/svg/mapcomplete_logo.svg",
"Go back to the theme overview",
{url: window.location.protocol+"//"+ window.location.hostname+"/index.html", newTab: false})
])
.SetClass("flex flex-col")
.AttachTo("centermessage");
throw e;
}
}