From e18eb06f14c1b29eec0e8bdff77e3337d7103685 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 22 Sep 2021 17:29:50 +0200 Subject: [PATCH] Add better error handling, fixes #452 --- InitUiElements.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index e3e61ce2ee..f6a6ce803f 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -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 ): [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:
" + 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; } }