diff --git a/src/matrix/storage/common.js b/src/matrix/storage/common.js index 4a6c0a21..aee08158 100644 --- a/src/matrix/storage/common.js +++ b/src/matrix/storage/common.js @@ -13,7 +13,7 @@ export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { }, {})); export class StorageError extends Error { - constructor(message, cause) { + constructor(message, cause, value) { let fullMessage = message; if (cause) { fullMessage += ": "; @@ -26,5 +26,7 @@ export class StorageError extends Error { if (cause) { this.errcode = cause.name; } + this.cause = cause; + this.value = value; } } diff --git a/src/matrix/storage/idb/store.js b/src/matrix/storage/idb/store.js index 3634b42f..f2169fe3 100644 --- a/src/matrix/storage/idb/store.js +++ b/src/matrix/storage/idb/store.js @@ -93,12 +93,22 @@ export default class Store extends QueryTarget { return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName))); } - put(value) { - return reqAsPromise(this._idbStore.put(value)); + async put(value) { + try { + return await reqAsPromise(this._idbStore.put(value)); + } catch(err) { + const originalErr = err.cause; + throw new StorageError(`put on ${this._idbStore.name} failed`, originalErr, value); + } } - add(value) { - return reqAsPromise(this._idbStore.add(value)); + async add(value) { + try { + return await reqAsPromise(this._idbStore.add(value)); + } catch(err) { + const originalErr = err.cause; + throw new StorageError(`add on ${this._idbStore.name} failed`, originalErr, value); + } } delete(keyOrKeyRange) {