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,7 +215,6 @@ function _restoreFromLocalStorage() {
|
|||
|
||||
if (accessToken && userId && hsUrl) {
|
||||
console.log(`Restoring session for ${userId}`);
|
||||
try {
|
||||
return _doSetLoggedIn({
|
||||
userId: userId,
|
||||
deviceId: deviceId,
|
||||
|
@ -223,10 +222,9 @@ function _restoreFromLocalStorage() {
|
|||
homeserverUrl: hsUrl,
|
||||
identityServerUrl: isUrl,
|
||||
guest: isGuest,
|
||||
}, false).then(() => true);
|
||||
} catch (e) {
|
||||
}, false).catch((e) => {
|
||||
return _handleRestoreFailure(e);
|
||||
}
|
||||
}).then(() => true);
|
||||
} else {
|
||||
console.log("No previous session found.");
|
||||
return Promise.resolve(false);
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
},
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue