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/6616pull/21833/head
parent
05f1ca6942
commit
f70096b8fa
|
@ -215,18 +215,16 @@ function _restoreFromLocalStorage() {
|
||||||
|
|
||||||
if (accessToken && userId && hsUrl) {
|
if (accessToken && userId && hsUrl) {
|
||||||
console.log(`Restoring session for ${userId}`);
|
console.log(`Restoring session for ${userId}`);
|
||||||
try {
|
return _doSetLoggedIn({
|
||||||
return _doSetLoggedIn({
|
userId: userId,
|
||||||
userId: userId,
|
deviceId: deviceId,
|
||||||
deviceId: deviceId,
|
accessToken: accessToken,
|
||||||
accessToken: accessToken,
|
homeserverUrl: hsUrl,
|
||||||
homeserverUrl: hsUrl,
|
identityServerUrl: isUrl,
|
||||||
identityServerUrl: isUrl,
|
guest: isGuest,
|
||||||
guest: isGuest,
|
}, false).catch((e) => {
|
||||||
}, false).then(() => true);
|
|
||||||
} catch (e) {
|
|
||||||
return _handleRestoreFailure(e);
|
return _handleRestoreFailure(e);
|
||||||
}
|
}).then(() => true);
|
||||||
} else {
|
} else {
|
||||||
console.log("No previous session found.");
|
console.log("No previous session found.");
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
|
|
|
@ -41,10 +41,14 @@ export default React.createClass({
|
||||||
Modal.createTrackedDialog('Session Restore Error', 'Send Bug Report Dialog', BugReportDialog, {});
|
Modal.createTrackedDialog('Session Restore Error', 'Send Bug Report Dialog', BugReportDialog, {});
|
||||||
},
|
},
|
||||||
|
|
||||||
_continueClicked: function() {
|
_onContinueClick: function() {
|
||||||
this.props.onFinished(true);
|
this.props.onFinished(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onCancelClick: function() {
|
||||||
|
this.props.onFinished(false);
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
||||||
|
@ -81,8 +85,8 @@ export default React.createClass({
|
||||||
{ bugreport }
|
{ bugreport }
|
||||||
</div>
|
</div>
|
||||||
<DialogButtons primaryButton={_t("Continue anyway")}
|
<DialogButtons primaryButton={_t("Continue anyway")}
|
||||||
onPrimaryButtonClick={this._continueClicked} focus={shouldFocusContinueButton}
|
onPrimaryButtonClick={this._onContinueClick} focus={shouldFocusContinueButton}
|
||||||
onCancel={this.props.onFinished} />
|
onCancel={this._onCancelClick} />
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,6 +39,10 @@ module.exports = React.createClass({
|
||||||
focus: PropTypes.bool,
|
focus: PropTypes.bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onCancelClick: function() {
|
||||||
|
this.props.onCancel();
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
let primaryButtonClassName = "mx_Dialog_primary";
|
let primaryButtonClassName = "mx_Dialog_primary";
|
||||||
if (this.props.primaryButtonClass) {
|
if (this.props.primaryButtonClass) {
|
||||||
|
@ -53,7 +57,7 @@ module.exports = React.createClass({
|
||||||
{ this.props.primaryButton }
|
{ this.props.primaryButton }
|
||||||
</button>
|
</button>
|
||||||
{ this.props.children }
|
{ this.props.children }
|
||||||
<button onClick={this.props.onCancel}>
|
<button onClick={this._onCancelClick}>
|
||||||
{ _t("Cancel") }
|
{ _t("Cancel") }
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue