fix: something
This commit is contained in:
@@ -253,8 +253,11 @@ export default fp(async (app: FastifyInstance) => {
|
||||
{ error, serverId, serverUuid: server.serverUuid, socketId: socket.id },
|
||||
'Failed to send console command',
|
||||
);
|
||||
socket.emit('server:console:output', { line: '[error] Failed to send command' });
|
||||
const ack: ConsoleCommandAck = { requestId, ok: false, error: 'Failed to send command' };
|
||||
// The daemon explains *why* (server not running, no RCON password, …) —
|
||||
// showing that beats a generic failure the user cannot act on.
|
||||
const reason = daemonErrorReason(error);
|
||||
socket.emit('server:console:output', { line: `[error] ${reason}` });
|
||||
const ack: ConsoleCommandAck = { requestId, ok: false, error: reason };
|
||||
socket.emit('server:console:command:ack', ack);
|
||||
}
|
||||
});
|
||||
@@ -277,6 +280,15 @@ export default fp(async (app: FastifyInstance) => {
|
||||
});
|
||||
});
|
||||
|
||||
/** Strip the gRPC status prefix so the console shows the daemon's own wording. */
|
||||
function daemonErrorReason(error: unknown): string {
|
||||
const raw = error instanceof Error ? error.message.trim() : '';
|
||||
if (!raw) return 'Failed to send command';
|
||||
|
||||
const withoutStatus = raw.replace(/^\d+\s+[A-Z_]+:\s*/, '').trim();
|
||||
return withoutStatus || 'Failed to send command';
|
||||
}
|
||||
|
||||
async function hasConsolePermission(
|
||||
app: FastifyInstance,
|
||||
user: AccessTokenPayload,
|
||||
|
||||
Reference in New Issue
Block a user