mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-24 18:13:42 +01:00
Return collect response when fail put cache to storage (#7863)
* return collect response when fail put cache to storage * cleanup callback
This commit is contained in:
parent
cd1b90d223
commit
c3b40a6950
1 changed files with 8 additions and 10 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue