forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
38 lines (32 loc) · 1.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Dexie from 'dexie'
import { CollectionDefinitions } from '@worldbrain/storex'
import { StorageManager } from '../types'
export abstract class FeatureStorage {
protected collections: { [name: string]: CollectionDefinitions }
constructor(protected storageManager: StorageManager) {}
registerCollections() {
for (const name of Object.keys(this.collections || {})) {
this.storageManager.registry.registerCollection(
name,
this.collections[name],
)
}
}
}
/**
* Error hanlder captures `OpenFailedError`s relating to `createObjectStore` IDB issues,
* allowing all other errors to get thrown. We do this as some users experience a fatal issue
* with this error rendering the DB unusable, but spamming our sentry error tracker.
*/
export const initErrHandler = <T>(defReturnVal: T = null) => (
err: Dexie.DexieError,
) => {
if (
err.message === 'Data fetch failed' ||
(err.name === Dexie.errnames.OpenFailed &&
err.message.includes('createObjectStore'))
) {
return defReturnVal
}
throw err
}