show close code and reason on ws close

This commit is contained in:
slice 2018-07-13 19:33:53 -07:00
parent 0964133dbe
commit 5b33219f13
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
1 changed files with 5 additions and 5 deletions

View File

@ -77,8 +77,9 @@ export default class App extends Component {
this.subscribeToChannels();
};
this.websocket.onclose = () => {
log(`ws closed; attempting to reconnect in ${this.reconnectionTime}ms`);
this.websocket.onclose = ({ code, reason }) => {
log(`ws closed with code ${code} (reason: ${reason || '<none>'}); `
+ `attempting to reconnect in ${this.reconnectionTime}ms`);
setTimeout(() => this.connect(), this.reconnectionTime);
this.reconnectionTime *= 2;
};
@ -91,12 +92,11 @@ export default class App extends Component {
this.handlePacket(parsed);
};
this.websocket.onerror = (error) => {
log('ws error:', error);
this.websocket.onerror = (event) => {
log('ws error:', event);
};
}
_send(payload) {
this.websocket.send(JSON.stringify(payload));
}