From 0dffd71276292a47a1c0d122bb246bbad928d85c Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 24 Dec 2019 19:14:07 +0200 Subject: [PATCH] Import Dialog: log potential import errors to console and close dialog. --- src/Journals/ImportDialog.tsx | 54 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Journals/ImportDialog.tsx b/src/Journals/ImportDialog.tsx index aed6cad..7eaec92 100644 --- a/src/Journals/ImportDialog.tsx +++ b/src/Journals/ImportDialog.tsx @@ -108,32 +108,42 @@ class ImportDialog extends React.Component { reader.onabort = () => alert('file reading was aborted'); reader.onerror = () => alert('file reading has failed'); reader.onload = () => { - const fileText = reader.result as string; - const items = itemsCreator(fileText); - - const { syncJournal } = this.props; - const last = syncJournal.journalEntries.last() as EteSync.Entry; - const lastUid = last ? last.uid : null; - - // XXX implement chunked push most likely... - let prevUid = lastUid; - const journalItems = items.map((item) => { - const ret = createJournalEntry( - this.props.etesync, this.props.userInfo, syncJournal.journal, - prevUid, EteSync.SyncEntryAction.Add, item.toIcal()); - - prevUid = ret.uid; - return ret; - }); - - store.dispatch( - addEntries(this.props.etesync, syncJournal.journal.uid, journalItems, lastUid) - ).then(() => { + try { + const fileText = reader.result as string; + const items = itemsCreator(fileText); + + const { syncJournal } = this.props; + const last = syncJournal.journalEntries.last() as EteSync.Entry; + const lastUid = last ? last.uid : null; + + // XXX implement chunked push most likely... + let prevUid = lastUid; + const journalItems = items.map((item) => { + const ret = createJournalEntry( + this.props.etesync, this.props.userInfo, syncJournal.journal, + prevUid, EteSync.SyncEntryAction.Add, item.toIcal()); + + prevUid = ret.uid; + return ret; + }); + + store.dispatch( + addEntries(this.props.etesync, syncJournal.journal.uid, journalItems, lastUid) + ).then(() => { + if (this.props.onClose) { + this.setState({ loading: false }); + this.props.onClose(); + } + }); + } catch (e) { + console.error(e); + alert('An error has occurred, please contact developers.'); if (this.props.onClose) { this.setState({ loading: false }); this.props.onClose(); } - }); + throw e; + } }; this.setState({ loading: true });