2020-08-05 22:08:55 +05:30
|
|
|
/*
|
|
|
|
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 13:30:29 +05:30
|
|
|
export const STORE_NAMES = Object.freeze([
|
|
|
|
"session",
|
|
|
|
"roomState",
|
|
|
|
"roomSummary",
|
2020-06-27 02:56:24 +05:30
|
|
|
"roomMembers",
|
2019-07-01 13:30:29 +05:30
|
|
|
"timelineEvents",
|
|
|
|
"timelineFragments",
|
|
|
|
"pendingEvents",
|
|
|
|
]);
|
2019-04-04 12:57:31 +05:30
|
|
|
|
|
|
|
export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {
|
|
|
|
nameMap[name] = name;
|
|
|
|
return nameMap;
|
|
|
|
}, {}));
|
2019-06-27 01:30:50 +05:30
|
|
|
|
|
|
|
export class StorageError extends Error {
|
2019-10-13 01:49:16 +05:30
|
|
|
constructor(message, cause, value) {
|
2019-06-27 01:30:50 +05:30
|
|
|
let fullMessage = message;
|
|
|
|
if (cause) {
|
|
|
|
fullMessage += ": ";
|
2019-11-21 22:58:18 +05:30
|
|
|
if (typeof cause.name === "string") {
|
|
|
|
fullMessage += `(name: ${cause.name}) `;
|
|
|
|
}
|
|
|
|
if (typeof cause.code === "number") {
|
|
|
|
fullMessage += `(code: ${cause.name}) `;
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|
2020-08-18 20:57:40 +05:30
|
|
|
}
|
|
|
|
if (value) {
|
|
|
|
fullMessage += `(value: ${JSON.stringify(value)}) `;
|
|
|
|
}
|
|
|
|
if (cause) {
|
2019-06-27 01:30:50 +05:30
|
|
|
fullMessage += cause.message;
|
|
|
|
}
|
|
|
|
super(fullMessage);
|
2019-07-27 01:33:57 +05:30
|
|
|
if (cause) {
|
|
|
|
this.errcode = cause.name;
|
|
|
|
}
|
2019-10-13 01:49:16 +05:30
|
|
|
this.cause = cause;
|
|
|
|
this.value = value;
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|
2020-08-18 20:57:40 +05:30
|
|
|
|
|
|
|
get name() {
|
|
|
|
return "StorageError";
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|