Show session restore errors on the login screen

If we are unable to load the matrix session on startup, don't just get stuck at
a spinner; instead, show the error on the login screen.
This commit is contained in:
Richard van der Hoff 2016-09-01 11:08:40 +01:00
parent 5543c126e6
commit ba341c11fb
2 changed files with 35 additions and 13 deletions

View file

@ -13,6 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import q from 'q';
var React = require('react'); var React = require('react');
var Matrix = require("matrix-js-sdk"); var Matrix = require("matrix-js-sdk");
var Favico = require('favico.js'); var Favico = require('favico.js');
@ -164,6 +167,9 @@ module.exports = React.createClass({
// their mind & log back in) // their mind & log back in)
this.guestCreds = null; this.guestCreds = null;
// if the automatic session load failed, the error
this.sessionLoadError = null;
if (this.props.config.sync_timeline_limit) { if (this.props.config.sync_timeline_limit) {
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit; MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
} }
@ -191,13 +197,18 @@ module.exports = React.createClass({
window.addEventListener('resize', this.handleResize); window.addEventListener('resize', this.handleResize);
this.handleResize(); this.handleResize();
Lifecycle.loadSession({ q().then(() => {
realQueryParams: this.props.realQueryParams, return Lifecycle.loadSession({
fragmentQueryParams: this.props.startingFragmentQueryParams, realQueryParams: this.props.realQueryParams,
enableGuest: this.props.enableGuest, fragmentQueryParams: this.props.startingFragmentQueryParams,
guestHsUrl: this.getCurrentHsUrl(), enableGuest: this.props.enableGuest,
guestIsUrl: this.getCurrentIsUrl(), guestHsUrl: this.getCurrentHsUrl(),
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName, guestIsUrl: this.getCurrentIsUrl(),
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
});
}).catch((e) => {
console.error("Unable to load session", e);
this.sessionLoadError = e.message;
}).done(()=>{ }).done(()=>{
// stuff this through the dispatcher so that it happens // stuff this through the dispatcher so that it happens
// after the on_logged_in action. // after the on_logged_in action.
@ -1085,7 +1096,7 @@ module.exports = React.createClass({
onLoginClick={this.onLoginClick} /> onLoginClick={this.onLoginClick} />
); );
} else { } else {
return ( var r = (
<Login <Login
onLoggedIn={Lifecycle.setLoggedIn} onLoggedIn={Lifecycle.setLoggedIn}
onRegisterClick={this.onRegisterClick} onRegisterClick={this.onRegisterClick}
@ -1098,8 +1109,16 @@ module.exports = React.createClass({
onForgotPasswordClick={this.onForgotPasswordClick} onForgotPasswordClick={this.onForgotPasswordClick}
enableGuest={this.props.enableGuest} enableGuest={this.props.enableGuest}
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null} onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
/> initialErrorText={this.sessionLoadError}
/>
); );
// we only want to show the session load error the first time the
// Login component is rendered. This is pretty hacky but I can't
// think of another way to achieve it.
this.sessionLoadError = null;
return r;
} }
} }
}); });

View file

@ -52,12 +52,14 @@ module.exports = React.createClass({
// login shouldn't care how password recovery is done. // login shouldn't care how password recovery is done.
onForgotPasswordClick: React.PropTypes.func, onForgotPasswordClick: React.PropTypes.func,
onCancelClick: React.PropTypes.func, onCancelClick: React.PropTypes.func,
initialErrorText: React.PropTypes.string,
}, },
getInitialState: function() { getInitialState: function() {
return { return {
busy: false, busy: false,
errorText: null, errorText: this.props.initialErrorText,
loginIncorrect: false, loginIncorrect: false,
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl, enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl, enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
@ -116,7 +118,8 @@ module.exports = React.createClass({
onHsUrlChanged: function(newHsUrl) { onHsUrlChanged: function(newHsUrl) {
var self = this; var self = this;
this.setState({ this.setState({
enteredHomeserverUrl: newHsUrl enteredHomeserverUrl: newHsUrl,
errorText: null, // reset err messages
}, function() { }, function() {
self._initLoginLogic(newHsUrl); self._initLoginLogic(newHsUrl);
}); });
@ -125,7 +128,8 @@ module.exports = React.createClass({
onIsUrlChanged: function(newIsUrl) { onIsUrlChanged: function(newIsUrl) {
var self = this; var self = this;
this.setState({ this.setState({
enteredIdentityServerUrl: newIsUrl enteredIdentityServerUrl: newIsUrl,
errorText: null, // reset err messages
}, function() { }, function() {
self._initLoginLogic(null, newIsUrl); self._initLoginLogic(null, newIsUrl);
}); });
@ -160,7 +164,6 @@ module.exports = React.createClass({
enteredHomeserverUrl: hsUrl, enteredHomeserverUrl: hsUrl,
enteredIdentityServerUrl: isUrl, enteredIdentityServerUrl: isUrl,
busy: true, busy: true,
errorText: null, // reset err messages
loginIncorrect: false, loginIncorrect: false,
}); });
}, },