From c81bac1a4c9d004f1d1f7c4a48d08149f9939266 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Fri, 23 Jul 2021 10:47:40 +0530 Subject: [PATCH] Add try catch for event tile errors --- src/components/views/messages/CallEvent.tsx | 4 +- src/utils/exportUtils/HtmlExport.tsx | 56 ++++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/components/views/messages/CallEvent.tsx b/src/components/views/messages/CallEvent.tsx index c0be3b46bb..f760f29ea2 100644 --- a/src/components/views/messages/CallEvent.tsx +++ b/src/components/views/messages/CallEvent.tsx @@ -46,7 +46,7 @@ export default class CallEvent extends React.Component { super(props); this.state = { - callState: this.props.callEventGrouper.state, + callState: this.props.callEventGrouper?.state, silenced: false, }; } @@ -184,7 +184,7 @@ export default class CallEvent extends React.Component { render() { const event = this.props.mxEvent; const sender = event.sender ? event.sender.name : event.getSender(); - const isVoice = this.props.callEventGrouper.isVoice; + const isVoice = this.props.callEventGrouper?.isVoice; const callType = isVoice ? _t("Voice call") : _t("Video call"); const content = this.renderContent(this.state.callState); const className = classNames({ diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index 5b1b8ee8c7..6f2394242c 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -301,33 +301,41 @@ export default class HTMLExporter extends Exporter { protected async createMessageBody(mxEv: MatrixEvent, joined = false) { let eventTile: string; - - if (this.isAttachment(mxEv)) { - if (this.exportOptions.attachmentsIncluded) { - try { - const blob = await this.getMediaBlob(mxEv); - if (this.totalSize + blob.size > this.exportOptions.maxSize) { - eventTile = await this.getEventTile(this.createModifiedEvent(this.mediaOmitText, mxEv), joined); - } else { - this.totalSize += blob.size; - const filePath = this.getFilePath(mxEv); - eventTile = await this.getEventTile(mxEv, joined, filePath); - if (this.totalSize == this.exportOptions.maxSize) { - this.exportOptions.attachmentsIncluded = false; + try { + if (this.isAttachment(mxEv)) { + if (this.exportOptions.attachmentsIncluded) { + try { + const blob = await this.getMediaBlob(mxEv); + if (this.totalSize + blob.size > this.exportOptions.maxSize) { + eventTile = await this.getEventTile( + this.createModifiedEvent(this.mediaOmitText, mxEv), + joined, + ); + } else { + this.totalSize += blob.size; + const filePath = this.getFilePath(mxEv); + eventTile = await this.getEventTile(mxEv, joined, filePath); + if (this.totalSize == this.exportOptions.maxSize) { + this.exportOptions.attachmentsIncluded = false; + } + this.addFile(filePath, blob); } - this.addFile(filePath, blob); + } catch (e) { + console.log("Error while fetching file" + e); + eventTile = await this.getEventTile( + this.createModifiedEvent(_t("Error fetching file"), mxEv), + joined, + ); } - } catch (e) { - console.log("Error while fetching file" + e); - eventTile = await this.getEventTile( - this.createModifiedEvent(_t("Error fetching file"), mxEv), - joined, - ); + } else { + eventTile = await this.getEventTile(this.createModifiedEvent(this.mediaOmitText, mxEv), joined); } - } else { - eventTile = await this.getEventTile(this.createModifiedEvent(this.mediaOmitText, mxEv), joined); - } - } else eventTile = await this.getEventTile(mxEv, joined); + } else eventTile = await this.getEventTile(mxEv, joined); + } catch (e) { + // TODO: Handle callEvent errors + console.error(e); + eventTile = await this.getEventTile(this.createModifiedEvent("Error parsing HTML", mxEv), joined); + } return eventTile; }