mirror of https://github.com/vector-im/riot-web
Wrap exception handling around all of loadSession
The user might (probably does) have a session even if we haven't actually tried to load it yet, so wrap the whole loadSession code in the error handler we were using for restoring sessions so we gracefully handle exceptions that happen before trying to restore sessions too. Remove the catch in MatrixChat that sent you to the login screen. This is never the right way to handle an error condition: we should only display the login screen if we successfully determined that the user has no session, or they explicitly chose to blow their sessions away.pull/21833/head
parent
db1401f484
commit
0323f8ed0c
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -65,6 +66,7 @@ import sdk from './index';
|
|||
* failed.
|
||||
*/
|
||||
export function loadSession(opts) {
|
||||
return new Promise.resolve().then(() => {
|
||||
const fragmentQueryParams = opts.fragmentQueryParams || {};
|
||||
let enableGuest = opts.enableGuest || false;
|
||||
const guestHsUrl = opts.guestHsUrl;
|
||||
|
@ -89,8 +91,8 @@ export function loadSession(opts) {
|
|||
guest: true,
|
||||
}, true).then(() => true);
|
||||
}
|
||||
|
||||
return _restoreFromLocalStorage().then((success) => {
|
||||
return _restoreFromLocalStorage();
|
||||
}).then((success) => {
|
||||
if (success) {
|
||||
return true;
|
||||
}
|
||||
|
@ -101,6 +103,8 @@ export function loadSession(opts) {
|
|||
|
||||
// fall back to login screen
|
||||
return false;
|
||||
}).catch((e) => {
|
||||
return _handleLoadSessionFailure(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -196,6 +200,7 @@ function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) {
|
|||
// SessionStore to avoid bugs where the view becomes out-of-sync with
|
||||
// localStorage (e.g. teamToken, isGuest etc.)
|
||||
function _restoreFromLocalStorage() {
|
||||
return Promise.resolve().then(() => {
|
||||
if (!localStorage) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
@ -222,17 +227,16 @@ function _restoreFromLocalStorage() {
|
|||
homeserverUrl: hsUrl,
|
||||
identityServerUrl: isUrl,
|
||||
guest: isGuest,
|
||||
}, false).catch((e) => {
|
||||
return _handleRestoreFailure(e);
|
||||
}).then(() => true);
|
||||
}, false).then(() => true);
|
||||
} else {
|
||||
console.log("No previous session found.");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _handleRestoreFailure(e) {
|
||||
console.log("Unable to restore session", e);
|
||||
function _handleLoadSessionFailure(e) {
|
||||
console.log("Unable to load session", e);
|
||||
|
||||
const def = Promise.defer();
|
||||
const SessionRestoreErrorDialog =
|
||||
|
@ -253,7 +257,7 @@ function _handleRestoreFailure(e) {
|
|||
}
|
||||
|
||||
// try, try again
|
||||
return _restoreFromLocalStorage();
|
||||
return loadSession();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
Copyright 2017 New Vector Ltd
|
||||
Copyright 2017, 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -351,15 +351,15 @@ export default React.createClass({
|
|||
guestIsUrl: this.getCurrentIsUrl(),
|
||||
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error('Error attempting to load session', e);
|
||||
return false;
|
||||
}).then((loadedSession) => {
|
||||
if (!loadedSession) {
|
||||
// fall back to showing the login screen
|
||||
dis.dispatch({action: "start_login"});
|
||||
}
|
||||
});
|
||||
// Note we don't catch errors from this: we catch everything within
|
||||
// loadSession as there's logic there to ask the user if they want
|
||||
// to try logging out.
|
||||
}).done();
|
||||
},
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
Loading…
Reference in New Issue