about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHinaloe <hina@hinaloe.net>2018-06-21 03:55:17 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-06-20 20:55:17 +0200
commitc3b40a6950f5e77813c292fc9997cf24b58130ea (patch)
treedf3e89b4cdb931d3fd282d2f260f0ac68bce68b4
parentcd1b90d22326972e31698c2cb9056a833995a08c (diff)
Return collect response when fail put cache to storage (#7863)
* return collect response when fail put cache to storage

* cleanup callback
-rw-r--r--app/javascript/mastodon/service_worker/entry.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js
index 2435da117..17b05a837 100644
--- a/app/javascript/mastodon/service_worker/entry.js
+++ b/app/javascript/mastodon/service_worker/entry.js
@@ -32,8 +32,11 @@ self.addEventListener('fetch', function(event) {
     const asyncCache = openWebCache();
 
     event.respondWith(asyncResponse.then(
-      response => asyncCache.then(cache => cache.put('/', response.clone()))
-        .then(() => response),
+      response => {
+        const clonedResponse = response.clone();
+        asyncCache.then(cache => cache.put('/', clonedResponse)).catch();
+        return response;
+      },
       () => asyncCache.then(cache => cache.match('/'))));
   } else if (url.pathname === '/auth/sign_out') {
     const asyncResponse = fetch(event.request);
@@ -58,14 +61,9 @@ self.addEventListener('fetch', function(event) {
 
           return asyncResponse.then(response => {
             if (response.ok) {
-              const put = cache.put(event.request.url, response.clone());
-
-              put.catch(() => freeStorage());
-
-              return put.then(() => {
-                freeStorage();
-                return response;
-              });
+              cache
+                .put(event.request.url, response.clone())
+                .catch(()=>{}).then(freeStorage()).catch();
             }
 
             return response;