Browse Source

Add error messages on bad status codes.

Bentley James Oakes 6 years ago
parent
commit
f07116d0a2
2 changed files with 37 additions and 16 deletions
  1. 30 16
      client/data_utils.js
  2. 7 0
      client/file_browser.js

+ 30 - 16
client/data_utils.js

@@ -273,19 +273,29 @@ DataUtils = function(){
 	 * 
 	 * @param bm - the button model to load
 	 */
-	this.loadbm = function(bm){
-		HttpUtils.httpReq(
-				'GET',
-				HttpUtils.url(bm,true),
-				undefined,
-				function(statusCode,resp)
-				{
-					GUIUtils.setupAndShowToolbar(
-						bm,
-						eval('('+resp+')'),
-						__BUTTON_TOOLBAR);					
-				});	
-	};
+    this.loadbm = function (bm) {
+        HttpUtils.httpReq(
+            'GET',
+            HttpUtils.url(bm, true),
+            undefined,
+            function (statusCode, resp) {
+                if (!utils.isHttpSuccessCode(statusCode)) {
+
+                    if (resp.includes("ENOENT")) {
+                        let err_msg = "Error! File not found: " + bm;
+                        WindowManagement.openDialog(_ERROR, err_msg);
+                    } else {
+                        WindowManagement.openDialog(_ERROR, resp);
+                    }
+                    return;
+                }
+
+                GUIUtils.setupAndShowToolbar(
+                    bm,
+                    eval('(' + resp + ')'),
+                    __BUTTON_TOOLBAR);
+            });
+    };
 	
 	/* 
 		1. does the deed
@@ -327,10 +337,14 @@ DataUtils = function(){
                                 DataUtils.loadm(fname, insert);
                             }
                         });
+                } else {
+                    if (resp.includes("cannot read")) {
+                        let err_msg = "Error! File cannot be read: " + fname;
+                        WindowManagement.openDialog(_ERROR, err_msg);
+                    } else {
+                        WindowManagement.openDialog(_ERROR, resp);
+                    }
                 }
-                else
-                    WindowManagement.openDialog(_ERROR, resp);
-
 
             });
     };

+ 7 - 0
client/file_browser.js

@@ -6,6 +6,13 @@ class FileBrowser{
             HttpUtils.url('/filelist', __NO_WID),
             undefined,
             function (statusCode, resp) {
+
+                if (statusCode == 404){
+                    let err_msg = "Error! Cannot load file list!";
+                    WindowManagement.openDialog(_ERROR, err_msg);
+                    return;
+                }
+
                 extensions.push('/');
                 var fnames = __localizeFilenames(
                     __filterFilenamesByExtension(