Skip to content

Commit

Permalink
feat: retry login 3 times before failing [ch18095] (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
seavan authored Jan 1, 2019
1 parent 06d2edc commit 870b4a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions app/components/layout/loading-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ const logoHeight = 72; // Logo in the animation
const logoAnimation = require('../../assets/loading_screens/loading-screen-logo-animation.json');
const revealAnimation = require('../../assets/loading_screens/loading-screen-reveal-animation.json');

async function retryLoginOperation(login, count) {
let i = 0;
for (;;) {
++i;
try {
return await login();
} catch (e) {
console.error(e);
console.log(`retry login: failed ${i} time out of ${count}`);
if (i >= count) {
console.log(`failing automatic login after ${i} tries`);
throw e;
}
}
}
}

@observer
export default class LoadingScreen extends Component {
@observable authenticated = false;
Expand All @@ -27,8 +44,10 @@ export default class LoadingScreen extends Component {

async componentDidMount() {
try {
await loginState.load();
if (!loginState.loaded) throw new Error('error logging in after return');
await retryLoginOperation(async () => {
await loginState.load();
if (!loginState.loaded) throw new Error('error logging in after return');
}, 3);
await promiseWhen(() => socket.authenticated);
this.authenticated = true;
await promiseWhen(() => routes.main.chatStateLoaded);
Expand Down
4 changes: 2 additions & 2 deletions app/components/login/login-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class LoginState extends RoutedState {
return true;
}

async load() {
load = async () => {
console.log(`login-state.js: loading`);
setTimeout(() => {
this.isInProgress = false;
Expand Down Expand Up @@ -218,7 +218,7 @@ class LoginState extends RoutedState {
setTimeout(() => {
this.isInProgress = false;
}, 0);
}
};

@action
async loadFromKeychain() {
Expand Down

0 comments on commit 870b4a4

Please sign in to comment.