Improve on remote failure handling

Change-Id: Ieeea4778612aa61cf4b3bfcf32b6909c5b671772
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index 5295b3c..5b30870 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -41,9 +41,9 @@
     if (param['spans'] == true) {
       url += '?spans=true';
       if (param['foundry'] !== undefined)
-	url += '&foundry=' + param['foundry'];
+	      url += '&foundry=' + param['foundry'];
       if (param['layer'] !== undefined)
-	url += '&layer=' + param['layer'];
+	      url += '&layer=' + param['layer'];
     }
     
     // { spans : false, layer: [Array of KorAP.InfoLayer] }
@@ -67,7 +67,6 @@
    */
   KorAP.API.getJSON = function (url, onload) {
     var req = new XMLHttpRequest();
-
     req.open("GET", url, true);
     req.setRequestHeader("Accept", "application/json");
     req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 
@@ -81,17 +80,23 @@
 	4 - done
       */
       if (this.readyState == 4) {
-	if (this.status === 200) {
-	  var json = JSON.parse(this.responseText);
-	  if (json["errors"] !== null) {
-	    for (var i in json["errors"]) {
-	      KorAP.log(json["errors"][i][0], json["errors"][i][1]);
-	    };
-	  };
-	  onload(json);
-	}
-	else
-	  KorAP.log(this.status, this.statusText);
+
+        var json = JSON.parse(this.responseText);
+	      if (json !== null && json["errors"] !== null) {
+	        for (var i in json["errors"]) {
+	          KorAP.log(json["errors"][i][0], json["errors"][i][1] || "Unknown");
+	        };
+	      }
+        else if (this.status !== 200) {
+        	KorAP.log(this.status, this.statusText);
+        };
+
+	      if (this.status === 200) {
+	        onload(json);
+	      }
+	      else {
+          onload(undefined);
+        };
       }
     };
     req.ontimeout = function () {
diff --git a/dev/js/src/match/info.js b/dev/js/src/match/info.js
index ab72778..743fa2c 100644
--- a/dev/js/src/match/info.js
+++ b/dev/js/src/match/info.js
@@ -114,6 +114,9 @@
 	      // Callback for retrieval
 	      function (matchResponse) {
 
+          if (matchResponse === undefined)
+            cb(null);
+
 	        // Get snippet from match info
 	        if (matchResponse["snippet"] !== undefined) {
 	          this._table = matchTableClass.create(matchResponse["snippet"]);
@@ -270,9 +273,9 @@
       this.getTable(undefined, function (table) {
 
 	      if (table !== null) {
-	        matchtable.classList.remove('loading');
           matchtable.appendChild(table.element());
 	      };
+	      matchtable.classList.remove('loading');
       });
 
       // Get spans