Show more info on web socket close

This commit is contained in:
Jannis Mattheis 2018-10-21 18:57:55 +02:00
parent b946ac2bc4
commit 42f1c34863
1 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import {SnackReporter} from '../snack/SnackManager';
import {CurrentUser} from '../CurrentUser';
import * as config from '../config';
import {AxiosError} from 'axios';
export class WebSocketStore {
private wsActive = false;
@ -32,10 +33,17 @@ export class WebSocketStore {
ws.onclose = () => {
this.wsActive = false;
this.currentUser.tryAuthenticate().then(() => {
this.snack('WebSocket connection closed, trying again in 30 seconds.');
setTimeout(this.listen, 30000);
});
this.currentUser
.tryAuthenticate()
.then(() => {
this.snack('WebSocket connection closed, trying again in 30 seconds.');
setTimeout(this.listen, 30000);
})
.catch((error: AxiosError) => {
if (error && error.response && error.response.status === 401) {
this.snack('Could not authenticate with client token, logging out.');
}
});
};
this.ws = ws;