From 2cd9c2344e2e238645bc1242a50d59c6aa489d54 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sat, 9 Mar 2019 00:43:43 +0100 Subject: [PATCH] expose timeline loading error in viewmodel --- src/domain/session/room/RoomViewModel.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index cec084b7..2e9c4053 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -6,12 +6,18 @@ export default class RoomViewModel extends EventEmitter { this._room = room; this._timeline = null; this._onRoomChange = this._onRoomChange.bind(this); + this._timelineError = null; } async enable() { this._room.on("change", this._onRoomChange); - this._timeline = await this._room.openTimeline(); - this.emit("change", "timelineEntries"); + try { + this._timeline = await this._room.openTimeline(); + this.emit("change", "timelineEntries"); + } catch (err) { + this._timelineError = err; + this.emit("change", "error"); + } } disable() { @@ -33,4 +39,11 @@ export default class RoomViewModel extends EventEmitter { get timelineEntries() { return this._timeline && this._timeline.entries; } + + get error() { + if (this._timelineError) { + return `Something went wrong loading the timeline: ${this._timelineError.message}`; + } + return null; + } }