diff --git a/package.json b/package.json index 160dc7b..351001c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.25.13", + "version": "0.25.14", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/cache.ts b/src/cache.ts index 00c48ed..9cc26aa 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -34,7 +34,12 @@ export class Cache { if(options.storageKey && !options.storage && typeof(Storage) !== 'undefined') options.storage = localStorage; if(options.storage) { if(options.storage instanceof Table) { - (async () => (await options.storage?.getAll()).forEach((v: any) => this.add(v)))() + (async () => (await options.storage?.getAll()).forEach((v: any) => { + if(v) { + try { this.add(v) } + catch { } + } + }))() } else if(options.storageKey) { const stored = options.storage?.getItem(options.storageKey); if(stored != null) try { Object.assign(this.store, JSON.parse(stored)); } catch { } @@ -55,6 +60,7 @@ export class Cache { private getKey(value: T): K { if(!this.key) throw new Error('No key defined'); + if(value[this.key] === undefined) throw new Error(`${this.key.toString()} Doesn't exist on ${JSON.stringify(value, null, 2)}`); return value[this.key]; }