Don't choke if the BugConnection returns bogus JSON
authorRichard Fairhurst <richard@systemeD.net>
Sun, 19 Jun 2011 09:50:05 +0000 (10:50 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 19 Jun 2011 09:50:05 +0000 (10:50 +0100)
net/systemeD/potlatch2/BugConnection.as

index 92bc578794be1e2b4b0a545f78122e36d8885147..f0e56a276aac3e7341427679d5082c051822c8ae 100644 (file)
@@ -83,24 +83,27 @@ package net.systemeD.potlatch2 {
         private function parseJSON(event:Event):void {
             var result:String = String(event.target.data);
             if (result) { // api returns 204 no content for no bugs, and the JSON parser treats '' as an error
-              var featureCollection:Object = JSON.decode(result);
-
-              for each (var feature:Object in featureCollection.features) {
-                // geoJSON spec is x,y,z i.e. lon, lat, ele
-                var lon:Number = feature.geometry.coordinates[0];
-                var lat:Number = feature.geometry.coordinates[1];
-                var tags:Object = {};
-                tags["name"] = String(feature.properties.description).substr(0,10)+'...';
-                tags["description"] = feature.properties.description;
-                tags["bug_id"] = feature.id;
-                tags["nickname"] = feature.properties.nickname;
-                tags["type"] = feature.properties.type;
-                tags["date_created"] = feature.properties.date_created;
-                tags["date_updated"] = feature.properties.date_updated;
-                tags["source"] = feature.properties.source;
-                tags["status"] = status[int(feature.properties.status)];
-                var marker:Marker = createMarker(tags, lat, lon, Number(feature.id));
-              }
+              try {
+                // wrap in a try/catch block in case we're given bogus JSON from the server
+                var featureCollection:Object = JSON.decode(result);
+
+                for each (var feature:Object in featureCollection.features) {
+                  // geoJSON spec is x,y,z i.e. lon, lat, ele
+                  var lon:Number = feature.geometry.coordinates[0];
+                  var lat:Number = feature.geometry.coordinates[1];
+                  var tags:Object = {};
+                  tags["name"] = String(feature.properties.description).substr(0,10)+'...';
+                  tags["description"] = feature.properties.description;
+                  tags["bug_id"] = feature.id;
+                  tags["nickname"] = feature.properties.nickname;
+                  tags["type"] = feature.properties.type;
+                  tags["date_created"] = feature.properties.date_created;
+                  tags["date_updated"] = feature.properties.date_updated;
+                  tags["source"] = feature.properties.source;
+                  tags["status"] = status[int(feature.properties.status)];
+                  var marker:Marker = createMarker(tags, lat, lon, Number(feature.id));
+                }
+              } catch (exception:Error) { }
             }
         }