]> cat aescling's git repositories - mastodon.git/commitdiff
Return collect response when fail put cache to storage (#7863)
authorHinaloe <hina@hinaloe.net>
Wed, 20 Jun 2018 18:55:17 +0000 (03:55 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 20 Jun 2018 18:55:17 +0000 (20:55 +0200)
* return collect response when fail put cache to storage

* cleanup callback

app/javascript/mastodon/service_worker/entry.js

index 2435da1170d70f46a3f7965f8e398dcc65757dff..17b05a837bfbe8ad758ed492e30f4f5c63bd7a74 100644 (file)
@@ -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;