wrap error and expose room id

this makes it easier to track down a (storage) error to a room
This commit is contained in:
Bruno Windels 2020-08-17 10:48:00 +02:00
parent b5e7131050
commit 306309c4f8
2 changed files with 18 additions and 2 deletions

View file

@ -14,6 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
export class WrappedError extends Error {
constructor(message, cause) {
super(`${message}: ${cause.message}`);
this.cause = cause;
}
get name() {
return "WrappedError";
}
}
export class HomeServerError extends Error { export class HomeServerError extends Error {
constructor(method, url, body, status) { constructor(method, url, body, status) {
super(`${body ? body.error : status} on ${method} ${url}`); super(`${body ? body.error : status} on ${method} ${url}`);

View file

@ -21,6 +21,7 @@ import {GapWriter} from "./timeline/persistence/GapWriter.js";
import {Timeline} from "./timeline/Timeline.js"; import {Timeline} from "./timeline/Timeline.js";
import {FragmentIdComparer} from "./timeline/FragmentIdComparer.js"; import {FragmentIdComparer} from "./timeline/FragmentIdComparer.js";
import {SendQueue} from "./sending/SendQueue.js"; import {SendQueue} from "./sending/SendQueue.js";
import {WrappedError} from "../error.js"
export class Room extends EventEmitter { export class Room extends EventEmitter {
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user}) { constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user}) {
@ -67,8 +68,12 @@ export class Room extends EventEmitter {
} }
load(summary, txn) { load(summary, txn) {
try {
this._summary.load(summary); this._summary.load(summary);
return this._syncWriter.load(txn); return this._syncWriter.load(txn);
} catch (err) {
throw new WrappedError(`Could not load room ${this._roomId}`, err);
}
} }
sendEvent(eventType, content) { sendEvent(eventType, content) {