forked from MapComplete/MapComplete
		
	Add better error handling, fixes #452
This commit is contained in:
		
							parent
							
								
									73f76881c4
								
							
						
					
					
						commit
						e18eb06f14
					
				
					 1 changed files with 18 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue