mirror of
https://github.com/unraid/api.git
synced 2026-01-13 03:59:58 -06:00
fix: disconnection reason being too long
This commit is contained in:
@@ -93,9 +93,7 @@ export class CustomSocket {
|
||||
customSocket.connectionAttempts = 0;
|
||||
} catch (error: unknown) {
|
||||
if (isNodeError(error, AppError)) {
|
||||
this.close(Number(error.code?.length === 4 ? error.code : `4${error.code ?? 500}`), JSON.stringify({
|
||||
message: error.message ?? 'Internal Server Error'
|
||||
}));
|
||||
this.close(Number(error.code?.length === 4 ? error.code : `4${error.code ?? 500}`), 'INTERNAL_SERVER_ERROR');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -140,7 +138,7 @@ export class CustomSocket {
|
||||
try {
|
||||
if (this.connection && (this.connection.readyState !== this.connection.CLOSED)) {
|
||||
// 4200 === ok
|
||||
this.connection.close(4200);
|
||||
this.connection.close(4200, 'OK');
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
this.logger.error('Failed disconnecting reason=%s', (error as Error).message);
|
||||
@@ -255,9 +253,7 @@ export class CustomSocket {
|
||||
protected async cleanup() {
|
||||
// Kill existing socket connection
|
||||
if (this.connection?.heartbeat) {
|
||||
this.connection.close(4200, JSON.stringify({
|
||||
message: 'Reconnecting'
|
||||
}));
|
||||
this.connection.close(4408, 'REQUEST_TIMEOUT');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,7 @@ export class InternalGraphql extends CustomSocket {
|
||||
return async function (this: WebSocketWithHeartBeat) {
|
||||
// No API key, close internal connection
|
||||
if (!apiKey) {
|
||||
this.close(4200, JSON.stringify({
|
||||
message: 'No API key'
|
||||
}));
|
||||
this.close(4403, 'FORBIDDEN');
|
||||
}
|
||||
|
||||
// Authenticate with ourselves
|
||||
|
||||
@@ -6,7 +6,6 @@ import { subscribeToServers } from '../subscribe-to-servers';
|
||||
import { AppError } from '../../core/errors';
|
||||
import { readFileIfExists } from '../utils';
|
||||
import { CustomSocket, WebSocketWithHeartBeat } from '../custom-socket';
|
||||
import { sockets } from '../../sockets';
|
||||
|
||||
export class MothershipSocket extends CustomSocket {
|
||||
private mothershipServersEndpoint?: {
|
||||
@@ -36,9 +35,7 @@ export class MothershipSocket extends CustomSocket {
|
||||
} catch (error: unknown) {
|
||||
if (isNodeError(error, AppError)) {
|
||||
const code = (error.code) ?? 500;
|
||||
this.close(`${code}`.length === 4 ? Number(code) : Number(`4${code}`), JSON.stringify({
|
||||
message: error.message ?? 'Internal Server Error'
|
||||
}));
|
||||
this.close(`${code}`.length === 4 ? Number(code) : Number(`4${code}`), 'INTERNAL_SERVER_ERROR');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -111,7 +108,7 @@ export class MothershipSocket extends CustomSocket {
|
||||
logger.error('socket error', error);
|
||||
} finally {
|
||||
// Kick the connection
|
||||
this.close(4500, JSON.stringify({ message: error.message }));
|
||||
this.close(4408, 'REQUEST_TIMEOUT');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user