Author: mhermanto
Date: Mon Dec 20 19:10:29 2010
New Revision: 1051245

URL: http://svn.apache.org/viewvc?rev=1051245&view=rev
Log:
CC: Update to error handling of navigation/preload of invalid gadgets
http://codereview.appspot.com/3660042/



Modified:
    shindig/trunk/features/src/main/javascript/features/container/container.js
    
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
    shindig/trunk/features/src/main/javascript/features/container/gadget_site.js

Modified: 
shindig/trunk/features/src/main/javascript/features/container/container.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1051245&r1=1051244&r2=1051245&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js 
(original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js 
Mon Dec 20 19:10:29 2010
@@ -175,10 +175,9 @@ shindig.container.Container.prototype.na
     // TODO: Should display error without doing a standard navigate.
     // TODO: Bad if the error gadget fails to load.
     if (gadgetInfo.error) {
-      throw ['Failed to possibly schedule token refresh for gadget ',
-          holder.getUrl(), '.'].join('');
-    }
-    if (gadgetInfo[shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
+      gadgets.warn(['Failed to possibly schedule token refresh for gadget ',
+          gadgetUrl, '.'].join(''));
+    } else if 
(gadgetInfo[shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
       self.scheduleRefreshTokens_();
     }
     callback(gadgetInfo);
@@ -224,12 +223,13 @@ shindig.container.Container.prototype.pr
   this.service_.getGadgetMetadata(request, function(response) {
     for (var id in response) {
       if (response[id].error) {
-        throw ['Failed to preload gadget ', id, '.'].join('');
-      }
-      self.addPreloadedGadgetUrl_(id);
-      if 
(response[id][shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
-        // Safe to re-schedule many times.
-        self.scheduleRefreshTokens_();
+        gadgets.warn(['Failed to preload gadget ', id, '.'].join(''));
+      } else {
+        self.addPreloadedGadgetUrl_(id);
+        if 
(response[id][shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
+          // Safe to re-schedule many times.
+          self.scheduleRefreshTokens_();
+        }
       }
     }
     callback(response);
@@ -576,12 +576,12 @@ shindig.container.Container.prototype.re
       if (gadgetInfo[shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
         var tokenInfo = response[holder.getUrl()];
         if (tokenInfo.error) {
-          throw ['Failed to get token for gadget ', holder.getUrl(), 
'.'].join('');
+          gadgets.warn(['Failed to get token for gadget ', holder.getUrl(), 
'.'].join(''));
+        } else {
+          gadgets.rpc.call(holder.getIframeId(), 'update_security_token', null,
+              tokenInfo[shindig.container.TokenResponse.TOKEN]);
         }
-        gadgets.rpc.call(holder.getIframeId(), 'update_security_token', null,
-            tokenInfo[shindig.container.TokenResponse.TOKEN]);
       }
     }
-    // TODO: Tokens will be stale, but error should not be ignored.
   });
 };

Modified: 
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js?rev=1051245&r1=1051244&r2=1051245&view=diff
==============================================================================
--- 
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js 
(original)
+++ 
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js 
Mon Dec 20 19:10:29 2010
@@ -289,7 +289,10 @@ shindig.container.GadgetHolder.prototype
   for (var key in iframeParams) {
     var value = iframeParams[key];
     if (value) {
-      out.push(key + '="' + value + '" ');
+      out.push(key);
+      out.push('="');
+      out.push(value);
+      out.push('" ');
     }
   }
   out.push('></iframe>');

Modified: 
shindig/trunk/features/src/main/javascript/features/container/gadget_site.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_site.js?rev=1051245&r1=1051244&r2=1051245&view=diff
==============================================================================
--- 
shindig/trunk/features/src/main/javascript/features/container/gadget_site.js 
(original)
+++ 
shindig/trunk/features/src/main/javascript/features/container/gadget_site.js 
Mon Dec 20 19:10:29 2010
@@ -247,25 +247,29 @@ shindig.container.GadgetSite.prototype.r
   if (curUrl == gadgetInfo['url']) {
     previousView = this.currentGadgetHolder_.getView();
   }
-
-  // Load into the double-buffer if there is one.
-  var el = this.loadingGadgetEl_ || this.currentGadgetEl_;
-  this.loadingGadgetHolder_ = new shindig.container.GadgetHolder(this.id_, el);
-
+  
   // Find requested view.
   var view = renderParams[shindig.container.RenderParam.VIEW]
       || viewParams[shindig.container.ViewParam.VIEW]
       || previousView;
   var viewInfo = gadgetInfo[shindig.container.MetadataResponse.VIEWS][view];
 
+  // Allow default view if requested view is not found.
   if (!viewInfo && 
renderParams[shindig.container.RenderParam.ALLOW_DEFAULT_VIEW]) {
     view = shindig.container.GadgetSite.DEFAULT_VIEW_;
     viewInfo = gadgetInfo[shindig.container.MetadataResponse.VIEWS][view];
   }
+
+  // Check if view exists.
   if (!viewInfo) {
-    throw ['Unsupported view ', view, ' for gadget ', gadgetInfo_['url'], 
'.'].join('');
+    gadgets.warn(['Unsupported view ', view, ' for gadget ', 
gadgetInfo['url'], '.'].join(''));
+    return;
   }
 
+  // Load into the double-buffer if there is one.
+  var el = this.loadingGadgetEl_ || this.currentGadgetEl_;
+  this.loadingGadgetHolder_ = new shindig.container.GadgetHolder(this.id_, el);
+
   var localRenderParams = {};
   for (var key in renderParams) {
     localRenderParams[key] = renderParams[key];


Reply via email to