mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
preserve value for storage errors on add and put
This commit is contained in:
parent
201b70ee4f
commit
b16f21867c
@ -13,7 +13,7 @@ export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {
|
|||||||
}, {}));
|
}, {}));
|
||||||
|
|
||||||
export class StorageError extends Error {
|
export class StorageError extends Error {
|
||||||
constructor(message, cause) {
|
constructor(message, cause, value) {
|
||||||
let fullMessage = message;
|
let fullMessage = message;
|
||||||
if (cause) {
|
if (cause) {
|
||||||
fullMessage += ": ";
|
fullMessage += ": ";
|
||||||
@ -26,5 +26,7 @@ export class StorageError extends Error {
|
|||||||
if (cause) {
|
if (cause) {
|
||||||
this.errcode = cause.name;
|
this.errcode = cause.name;
|
||||||
}
|
}
|
||||||
|
this.cause = cause;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,12 +93,22 @@ export default class Store extends QueryTarget {
|
|||||||
return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName)));
|
return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
put(value) {
|
async put(value) {
|
||||||
return reqAsPromise(this._idbStore.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) {
|
async add(value) {
|
||||||
return reqAsPromise(this._idbStore.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) {
|
delete(keyOrKeyRange) {
|
||||||
|
Loading…
Reference in New Issue
Block a user