From 7ab4969dd3866c693c99adf7eaffd8deeb028c8d Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Fri, 11 May 2012 12:20:15 -0600
Subject: [PATCH] when the server returns a 413 error for posting of
 interaction data, clear the data from local storage - issue #1567

---
 resources/static/shared/modules/interaction_data.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/resources/static/shared/modules/interaction_data.js b/resources/static/shared/modules/interaction_data.js
index 458478ed6..1ad832138 100644
--- a/resources/static/shared/modules/interaction_data.js
+++ b/resources/static/shared/modules/interaction_data.js
@@ -96,10 +96,21 @@ BrowserID.Modules.InteractionData = (function() {
   function publishStored(oncomplete) {
     var data = storage.get();
 
+    // XXX: should we even try to post data if it's larger than some reasonable
+    // threshold?
     if (data && data.length !== 0) {
       network.sendInteractionData(data, function() {
         storage.clear();
         complete(oncomplete, true);
+      }, function(status) {
+        // if the server returns a 413 error, (too much data posted), then
+        // let's clear our local storage and move on.  This does mean we
+        // loose some interaction data, but it shouldn't be statistically
+        // significant.
+        if (status && status.network && status.network.status === 413) {
+          storage.clear();
+        }
+        complete(oncomplete, false);
       });
     }
     else {
-- 
GitLab