try around parsing upc data master
authorOwen Smith <owen@omsmith.ca>
Sat, 24 Nov 2012 04:05:17 +0000 (23:05 -0500)
committerOwen Smith <owen@omsmith.ca>
Sat, 24 Nov 2012 04:05:17 +0000 (23:05 -0500)
www/assets/js/ui.js

index 0527b58..804780d 100644 (file)
@@ -110,5 +110,14 @@ ko.applyBindings(new SelectionsViewModel());
 
 function request_upc_data (upc, callback) {
        $.ajax( 'upc.php?upc=' + upc )
-               .done(function (data) { callback(JSON.parse(data)); });
+               .done(function (data) {
+                       var obj;
+                       try {
+                               obj = JSON.parse(data);
+                       } catch (e) {
+                               obj = { name:'unknown', size:'unknown' }
+                       }
+
+                       callback(obj);
+               });
 }