Fix error handling on session restore

Fix a number of failures that meant the excellent error handling
we had for failing to restore a session didn't work.

1. .catch on the promise rather than try/catch: it's async
2. Explicit cancel method in SessionRestoreErrorDialog that invokes
   onFinished with `false` because even with the catch fixed, this
   was getting the event as its first arg which is truthy, so
   clicking cancel still deleted your data.
3. DialogButtons: Don't pass onCancel straight into the button event
   handler as this leaks the MouseEvent through as an argument.
   Nothing is using it and it exacerbates failures like this
   because there are surprise arguments.

Fixes https://github.com/vector-im/riot-web/issues/6616
pull/21833/head
David Baker 2018-04-26 17:07:58 +01:00
parent 05f1ca6942
commit f70096b8fa
3 changed files with 21 additions and 15 deletions

View File

@ -215,18 +215,16 @@ function _restoreFromLocalStorage() {
if (accessToken && userId && hsUrl) {
console.log(`Restoring session for ${userId}`);
try {
return _doSetLoggedIn({
userId: userId,
deviceId: deviceId,
accessToken: accessToken,
homeserverUrl: hsUrl,
identityServerUrl: isUrl,
guest: isGuest,
}, false).then(() => true);
} catch (e) {
return _doSetLoggedIn({
userId: userId,
deviceId: deviceId,
accessToken: accessToken,
homeserverUrl: hsUrl,
identityServerUrl: isUrl,
guest: isGuest,
}, false).catch((e) => {
return _handleRestoreFailure(e);
}
}).then(() => true);
} else {
console.log("No previous session found.");
return Promise.resolve(false);

View File

@ -41,10 +41,14 @@ export default React.createClass({
Modal.createTrackedDialog('Session Restore Error', 'Send Bug Report Dialog', BugReportDialog, {});
},
_continueClicked: function() {
_onContinueClick: function() {
this.props.onFinished(true);
},
_onCancelClick: function() {
this.props.onFinished(false);
},
render: function() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
@ -81,8 +85,8 @@ export default React.createClass({
{ bugreport }
</div>
<DialogButtons primaryButton={_t("Continue anyway")}
onPrimaryButtonClick={this._continueClicked} focus={shouldFocusContinueButton}
onCancel={this.props.onFinished} />
onPrimaryButtonClick={this._onContinueClick} focus={shouldFocusContinueButton}
onCancel={this._onCancelClick} />
</BaseDialog>
);
},

View File

@ -39,6 +39,10 @@ module.exports = React.createClass({
focus: PropTypes.bool,
},
_onCancelClick: function() {
this.props.onCancel();
},
render: function() {
let primaryButtonClassName = "mx_Dialog_primary";
if (this.props.primaryButtonClass) {
@ -53,7 +57,7 @@ module.exports = React.createClass({
{ this.props.primaryButton }
</button>
{ this.props.children }
<button onClick={this.props.onCancel}>
<button onClick={this._onCancelClick}>
{ _t("Cancel") }
</button>
</div>