mirror of
https://github.com/unraid/api.git
synced 2026-01-12 19:50:07 -06:00
fix: use 401 when disconnecting for invalid api key
This commit is contained in:
@@ -56,7 +56,7 @@ export const myservers = () => {
|
||||
mothership.close(true, true);
|
||||
|
||||
// Disconnect from relay
|
||||
await sockets.get('relay')?.disconnect();
|
||||
await sockets.get('relay')?.disconnect(4401);
|
||||
}
|
||||
|
||||
// If we have a my_servers key reconnect to mothership
|
||||
|
||||
@@ -103,11 +103,11 @@ am(async () => {
|
||||
|
||||
// Disconnect relay
|
||||
apiManagerLogger.debug('Disconnecting relay');
|
||||
await sockets.get('relay')?.disconnect();
|
||||
await sockets.get('relay')?.disconnect(4401);
|
||||
|
||||
// Disconnect internal graphql
|
||||
apiManagerLogger.debug('Disconnecting internalGraphql');
|
||||
await sockets.get('internalGraphql')?.disconnect();
|
||||
await sockets.get('internalGraphql')?.disconnect(4401);
|
||||
} catch (error: unknown) {
|
||||
apiManagerLogger.error('Failed updating sockets on "expire" event with error %s.', error);
|
||||
}
|
||||
|
||||
@@ -142,10 +142,22 @@ export class CustomSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public async disconnect() {
|
||||
public async disconnect(code?: number, message?: string) {
|
||||
const lock = await this.getLock();
|
||||
try {
|
||||
if (this.connection && (this.connection.readyState !== this.connection.CLOSED)) {
|
||||
// Don't try and disconnect if there's no connection
|
||||
if (!this.connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's a custom code pass it to the close method
|
||||
if (code) {
|
||||
this.connection.close(code, message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback to a "ok" disconnect
|
||||
if (this.connection.readyState !== this.connection.CLOSED) {
|
||||
// 4200 === ok
|
||||
this.connection.close(4200, JSON.stringify({
|
||||
message: 'OK'
|
||||
|
||||
Reference in New Issue
Block a user