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 LayerConfig from "./Models/ThemeConfig/LayerConfig"; | ||||||
| import Minimap from "./UI/Base/Minimap"; | import Minimap from "./UI/Base/Minimap"; | ||||||
| import Constants from "./Models/Constants"; | import Constants from "./Models/Constants"; | ||||||
|  | import Combine from "./UI/Base/Combine"; | ||||||
|  | import {SubtleButton} from "./UI/Base/SubtleButton"; | ||||||
| 
 | 
 | ||||||
| export class InitUiElements { | export class InitUiElements { | ||||||
|     static InitAll( |     static InitAll( | ||||||
|  | @ -209,8 +211,8 @@ export class InitUiElements { | ||||||
|     static LoadLayoutFromHash( |     static LoadLayoutFromHash( | ||||||
|         userLayoutParam: UIEventSource<string> |         userLayoutParam: UIEventSource<string> | ||||||
|     ): [LayoutConfig, string] { |     ): [LayoutConfig, string] { | ||||||
|         try { |  | ||||||
|             let hash = location.hash.substr(1); |             let hash = location.hash.substr(1); | ||||||
|  |         try { | ||||||
|             const layoutFromBase64 = userLayoutParam.data; |             const layoutFromBase64 = userLayoutParam.data; | ||||||
|             // layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
 |             // 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); |             userLayoutParam.setData(layoutToUse.id); | ||||||
|             return [layoutToUse, btoa(Utils.MinifyJSON(JSON.stringify(json)))]; |             return [layoutToUse, btoa(Utils.MinifyJSON(JSON.stringify(json)))]; | ||||||
|         } catch (e) { |         } catch (e) { | ||||||
|             new FixedUiElement( |              | ||||||
|                 "Error: could not parse the custom layout:<br/> " + e |             if(hash === undefined || hash.length < 10){ | ||||||
|             ).AttachTo("centermessage"); |                 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; |             throw e; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue