Improved how we handle and report errors during startup.

master
Pacman Ghost 3 years ago
parent 0dbf1b0186
commit c078dcafa2
  1. 11
      vasl_templates/webapp/__init__.py
  2. 11
      vasl_templates/webapp/static/main.js
  3. 1
      vasl_templates/webapp/static/snippets.js
  4. 4
      vasl_templates/webapp/static/utils.js
  5. 2
      vasl_templates/webapp/static/vo.js
  6. 2
      vasl_templates/webapp/vo.py
  7. 4
      vasl_templates/webapp/vo_notes.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."""

@ -274,6 +274,7 @@ $(document).ready( function () {
}
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the application config:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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"
) ;

@ -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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
update_page_load_status( "default-scenario" ) ;
return ;
} ) ;
}

@ -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

@ -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] ;

@ -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

@ -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" ] )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Loading…
Cancel
Save