vector-im-hydrogen-web/src/matrix/storage/common.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-08-05 18:38:55 +02:00
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2019-07-01 10:00:29 +02:00
export const STORE_NAMES = Object.freeze([
"session",
"roomState",
"roomSummary",
2020-06-26 23:26:24 +02:00
"roomMembers",
2019-07-01 10:00:29 +02:00
"timelineEvents",
"timelineFragments",
"pendingEvents",
2020-08-31 14:38:03 +02:00
"userIdentities",
"deviceIdentities",
2020-09-01 17:59:59 +02:00
"olmSessions",
2020-09-02 14:24:38 +02:00
"inboundGroupSessions",
2020-09-03 17:49:20 +02:00
"outboundGroupSessions",
"groupSessionDecryptions",
2020-09-11 14:40:05 +02:00
"operations"
2019-07-01 10:00:29 +02:00
]);
2019-04-04 09:27:31 +02:00
export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {
nameMap[name] = name;
return nameMap;
}, {}));
export class StorageError extends Error {
constructor(message, cause, value) {
let fullMessage = message;
if (cause) {
fullMessage += ": ";
2019-11-21 18:28:18 +01:00
if (typeof cause.name === "string") {
fullMessage += `(name: ${cause.name}) `;
}
if (typeof cause.code === "number") {
2020-08-19 16:14:10 +02:00
fullMessage += `(code: ${cause.code}) `;
}
}
if (value) {
fullMessage += `(value: ${JSON.stringify(value)}) `;
}
if (cause) {
fullMessage += cause.message;
}
super(fullMessage);
2019-07-26 22:03:57 +02:00
if (cause) {
this.errcode = cause.name;
}
this.cause = cause;
this.value = value;
}
get name() {
return "StorageError";
}
}