From e191528c4cc5eefafb47bb141dbd3e939abfafa9 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Sat, 30 Sep 2023 19:03:11 +0300 Subject: [PATCH] catch idb write error in set and bulkSet --- packages/shared/src/feed-cache.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/shared/src/feed-cache.ts b/packages/shared/src/feed-cache.ts index 2ba22c1b..022bd4a0 100644 --- a/packages/shared/src/feed-cache.ts +++ b/packages/shared/src/feed-cache.ts @@ -12,7 +12,7 @@ export interface KeyedHookFilter { /** * Dexie backed generic hookable store */ -export abstract class FeedCache { +export abstract class FeedCache { #name: string; #hooks: Array = []; #snapshot: Array = []; @@ -109,16 +109,24 @@ export abstract class FeedCache { const k = this.key(obj); this.cache.set(k, obj); if (this.table) { - await this.table.put(obj); - this.onTable.add(k); + try { + await this.table.put(obj); + this.onTable.add(k); + } catch (e) { + console.error(e); + } } this.notifyChange([k]); } async bulkSet(obj: Array | Readonly>) { if (this.table) { - await this.table.bulkPut(obj); - obj.forEach(a => this.onTable.add(this.key(a))); + try { + await this.table.bulkPut(obj); + obj.forEach(a => this.onTable.add(this.key(a))); + } catch (e) { + console.error(e); + } } obj.forEach(v => this.cache.set(this.key(v), v)); this.notifyChange(obj.map(a => this.key(a)));