From 5f78657e51c9046dc61e1cf78b252e30fbb366d8 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 17 Feb 2020 17:25:42 +0200 Subject: [PATCH] Fix crash with associate accounts. Associates accounts can't create journals, and the web client was failing for them because the creation error wasn't being handled correctly. --- src/SyncGate.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/SyncGate.tsx b/src/SyncGate.tsx index a9d323f..1e61194 100644 --- a/src/SyncGate.tsx +++ b/src/SyncGate.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { connect } from 'react-redux'; -import { Action } from 'redux-actions'; import { Route, Switch, Redirect, RouteComponentProps, withRouter } from 'react-router'; import moment from 'moment'; @@ -118,13 +117,17 @@ class SyncGate extends React.PureComponent { const journal = new EteSync.Journal({ uid: collection.uid }); const cryptoManager = new EteSync.CryptoManager(this.props.etesync.encryptionKey, collection.uid); journal.setInfo(cryptoManager, collection); - store.dispatch(addJournal(this.props.etesync, journal)).then( - (journalAction: Action) => { - // FIXME: Limit based on error code to only do it for associates. - if (!journalAction.error) { - store.dispatch(fetchEntries(this.props.etesync, collection.uid)); - } - }); + (async () => { + try { + const addedJournalAction = addJournal(this.props.etesync, journal); + await addedJournalAction.payload; + store.dispatch(addedJournalAction); + store.dispatch(fetchEntries(this.props.etesync, collection.uid)); + } catch (e) { + // FIXME: Limit based on error code to only ignore for associates + console.warn(`Failed creating journal for ${collection.type}. Associate?`); + } + })(); }); }); };