Permalink
Browse files

Added error handling.

  • Loading branch information...
1 parent de673ae commit 16bda57877a89b09a96c074ca732aa63828efcea @rishabhsrao committed Dec 8, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 js/main.js
View
@@ -44,11 +44,21 @@ jQuery(document).ready(function() {
// so we can use KnockoutJS's convenience method removeAll()
self.items.removeAll();
- // Apply bindings to self.items
- jQuery.each(data.Similar.Results, function(index, value) {
- var item = new ItemModel(value);
- self.items.push(item);
- });
+ if(data && data.Similar && data.Similar.Results) {
+ if(0 !== data.Similar.Results.length) {
+ // Apply bindings to self.items
+ jQuery.each(data.Similar.Results, function(index, value) {
+ var item = new ItemModel(value);
+ self.items.push(item);
+ });
+ } else {
+ var item = new ItemModel({
+ "Name": "No data found",
+ "Type": ""
+ });
+ self.items.push(item);
+ }
+ }
}
});
};

0 comments on commit 16bda57

Please sign in to comment.