catch error when cache access fails

This commit is contained in:
Abhinav 2022-01-27 12:27:01 +05:30
parent 69a193a5c0
commit 8ebb34c56d
2 changed files with 27 additions and 10 deletions

View file

@ -24,8 +24,16 @@ class DownloadManager {
}
if (!this.thumbnailObjectURLPromise.get(file.id)) {
const downloadPromise = async () => {
const thumbnailCache = await caches.open('thumbs');
const cacheResp: Response = await thumbnailCache.match(
const thumbnailCache = await (async () => {
try {
return await caches.open('thumbs');
} catch (e) {
logError(e, 'cache open failed');
return null;
}
})();
const cacheResp: Response = await thumbnailCache?.match(
file.id.toString()
);
if (cacheResp) {
@ -34,7 +42,7 @@ class DownloadManager {
const thumb = await this.downloadThumb(token, file);
const thumbBlob = new Blob([thumb]);
try {
await thumbnailCache.put(
await thumbnailCache?.put(
file.id.toString(),
new Response(thumbBlob)
);

View file

@ -72,13 +72,22 @@ export const setRecoveryKey = (token: string, recoveryKey: RecoveryKey) =>
});
export const logoutUser = async () => {
try {
// ignore server logout result as logoutUser can be triggered before sign up or on token expiry
await _logout();
clearKeys();
clearData();
try {
await caches.delete('thumbs');
} catch (e) {
logError(e, 'cache delete failed');
// ignore
}
await clearFiles();
router.push(PAGES.ROOT);
} catch (e) {
logError(e, 'logoutUser failed');
}
};
export const clearFiles = async () => {