fix: dont reconnect on 401

This commit is contained in:
Alexis Tyler
2021-06-01 18:04:09 +09:30
parent 19b26d7843
commit 83cbd678f7

View File

@@ -178,6 +178,7 @@ export class CustomSocket {
protected onDisconnect() {
// Connection attempts
let connectionAttempts = this.connectionAttempts;
let shouldReconnect = true;
const logger = this.logger;
const connect = this.connect.bind(this);
@@ -210,6 +211,7 @@ export class CustomSocket {
// Unauthorized - Invalid/missing API key.
4401: async () => {
this.logger.debug('Invalid API key, waiting for new key...');
shouldReconnect = false;
},
// Request Timeout - Mothership disconnected us.
4408: async () => {
@@ -285,6 +287,11 @@ export class CustomSocket {
logger.error('Connection closed with code=%s reason="%s"', code, (error as Error).message);
}
// We shouldn't reconnect
if (!shouldReconnect) {
return;
}
try {
// Wait a few seconds
await sleep(backoff(connectionAttempts, ONE_MINUTE, 5));