diff --git a/vasl_templates/webapp/__init__.py b/vasl_templates/webapp/__init__.py index 5a713c6..f4ede85 100644 --- a/vasl_templates/webapp/__init__.py +++ b/vasl_templates/webapp/__init__.py @@ -36,8 +36,15 @@ def _on_request(): with _init_lock: global _init_done if not _init_done or (request.path == "/" and request.args.get("force-reinit")): - _init_webapp() - _init_done = True + try: + _init_webapp() + except Exception as ex: #pylint: disable=broad-except + from vasl_templates.webapp.main import startup_msg_store #pylint: disable=cyclic-import + startup_msg_store.error( str(ex) ) + finally: + # NOTE: It's important to set this, even if initialization failed, so we don't + # try to initialize again. + _init_done = True def _init_webapp(): """Do startup initialization.""" diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 1119f34..0c7140a 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -274,6 +274,7 @@ $(document).ready( function () { } } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the application config:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "app-config" ) ; } ) ; // get the vehicle/ordnance listings @@ -282,24 +283,28 @@ $(document).ready( function () { update_page_load_status( "vehicle-listings" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the vehicle listings:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "vehicle-listings" ) ; } ) ; $.getJSON( gOrdnanceListingsUrl, function(data) { gVehicleOrdnanceListings.ordnance = data ; update_page_load_status( "ordnance-listings" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the ordnance listings:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "ordnance-listings" ) ; } ) ; $.getJSON( gVehicleNotesUrl, function(data) { gVehicleOrdnanceNotes.vehicles = data ; update_page_load_status( "vehicle-notes" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the vehicle notes:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "vehicle-notes" ) ; } ) ; $.getJSON( gOrdnanceNotesUrl, function(data) { gVehicleOrdnanceNotes.ordnance = data ; update_page_load_status( "ordnance-notes" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the ordnance notes:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "ordnance-notes" ) ; } ) ; // get the VASL piece info @@ -308,6 +313,7 @@ $(document).ready( function () { update_page_load_status( "vasl-piece-info" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the VASL piece info:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "vasl-piece-info" ) ; } ) ; // get the template pack @@ -328,6 +334,7 @@ $(document).ready( function () { update_page_load_status( "template-pack" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the template pack:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "template-pack" ) ; } ) ; // fixup the layout @@ -727,6 +734,8 @@ function on_player_change( player_no ) // show/hide the vehicle/ordnance multi-applicable notes controls function update_ma_notes_controls( vo_type ) { + if ( ! gTemplatePack.nationalities ) + return ; var show = ( gVehicleOrdnanceNotes[vo_type] && gVehicleOrdnanceNotes[vo_type][player_nat] ) || ["allied-minor","axis-minor"].indexOf( gTemplatePack.nationalities[ player_nat ].type ) !== -1 || player_nat === "free-french" ; @@ -749,6 +758,8 @@ function on_player_change( player_no ) // enable/disable the "add vehicle/ordnance" buttons function update_add_vo_button( vo_type ) { + if ( ! gVehicleOrdnanceListings[ vo_type ] ) + return ; $( "#ob_"+vo_type+"-add_"+player_no ).button( gVehicleOrdnanceListings[vo_type][player_nat] ? "enable": "disable" ) ; diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 2064b60..a519eab 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -1931,6 +1931,7 @@ function do_on_new_scenario( user_requested ) { update_page_load_status( "default-scenario" ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the default scenario:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "default-scenario" ) ; return ; } ) ; } diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 93a6c3a..84c0dd0 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -13,7 +13,7 @@ function make_app_url( url, for_snippet ) function get_nationality_display_name( nat_id ) { // get the nationality's display name - if ( ! gTemplatePack.nationalities[ nat_id ] ) + if ( ! gTemplatePack.nationalities || ! gTemplatePack.nationalities[nat_id] ) return null ; return gTemplatePack.nationalities[ nat_id ].display_name ; } @@ -62,6 +62,8 @@ function get_player_colors_for_element( $elem ) } function make_player_flag_url( nat, for_snippet ) { + if ( ! gTemplatePack.nationalities ) + return null ; var flag = gTemplatePack.nationalities[nat].flag ; if ( flag ) return flag ; // nb: custom flag, just use that diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index c7f9883..8b19c86 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -284,6 +284,8 @@ function find_vo( vo_type, nat, vo_id ) { // find the specificed vehicle/ordnance var entries = gVehicleOrdnanceListings[vo_type][nat] ; + if ( ! entries ) + return null ; for ( var i=0 ; i < entries.length ; ++i ) { if ( entries[i].id === vo_id ) return entries[i] ; diff --git a/vasl_templates/webapp/vo.py b/vasl_templates/webapp/vo.py index 26e2287..91654ce 100644 --- a/vasl_templates/webapp/vo.py +++ b/vasl_templates/webapp/vo.py @@ -29,6 +29,8 @@ def _do_get_listings( vo_type ): """Return the vehicle/ordnance listings.""" if request.args.get("merge_common") == "1" and request.args.get("report") != "1": # nb: this is the normal case + if not globvars.vo_listings: + abort( 404 ) return globvars.vo_listings[ vo_type ] else: # nb: we should only get here during tests diff --git a/vasl_templates/webapp/vo_notes.py b/vasl_templates/webapp/vo_notes.py index 7011e9f..c591b64 100644 --- a/vasl_templates/webapp/vo_notes.py +++ b/vasl_templates/webapp/vo_notes.py @@ -20,11 +20,15 @@ from vasl_templates.webapp.utils import resize_image_response, is_image_file, is @app.route( "/vehicles/notes" ) def get_vehicle_notes(): """Return the Chapter H vehicle notes.""" + if not globvars.vo_notes: + abort( 404 ) return jsonify( globvars.vo_notes[ "vehicles" ] ) @app.route( "/ordnance/notes" ) def get_ordnance_notes(): """Return the Chapter H ordnance notes.""" + if not globvars.vo_notes: + abort( 404 ) return jsonify( globvars.vo_notes[ "ordnance" ] ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -