mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(server): throw error when authentication fails
This commit is contained in:
@@ -24,41 +24,43 @@ export const execAsyncRemote = async (
|
||||
conn
|
||||
.once("ready", () => {
|
||||
console.log("Client :: ready");
|
||||
conn
|
||||
.exec(command, (err, stream) => {
|
||||
if (err) throw err;
|
||||
stream
|
||||
.on("close", (code: number, signal: string) => {
|
||||
console.log(
|
||||
`Stream :: close :: code: ${code}, signal: ${signal}`,
|
||||
conn.exec(command, (err, stream) => {
|
||||
if (err) throw err;
|
||||
stream
|
||||
.on("close", (code: number, signal: string) => {
|
||||
console.log(
|
||||
`Stream :: close :: code: ${code}, signal: ${signal}`,
|
||||
);
|
||||
conn.end();
|
||||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(
|
||||
new Error(
|
||||
`Command exited with code ${code}. Stderr: ${stderr}, command: ${command}`,
|
||||
),
|
||||
);
|
||||
conn.end();
|
||||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(
|
||||
new Error(
|
||||
`Command exited with code ${code}. Stderr: ${stderr}, command: ${command}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
})
|
||||
.on("data", (data: string) => {
|
||||
stdout += data.toString();
|
||||
})
|
||||
.stderr.on("data", (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
})
|
||||
.on("keyboard-interactive", () => {
|
||||
console.log("Warning: Keyboard interactive, closing connection");
|
||||
conn.end();
|
||||
reject(
|
||||
new Error(
|
||||
"Password requested. Invalid SSH key or authentication issue.",
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
})
|
||||
.on("data", (data: string) => {
|
||||
stdout += data.toString();
|
||||
})
|
||||
.stderr.on("data", (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
});
|
||||
})
|
||||
.on("error", (err) => {
|
||||
conn.end();
|
||||
if (err.level === "client-authentication") {
|
||||
reject(
|
||||
new Error(
|
||||
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
reject(new Error(`SSH connection error: ${err.message}`));
|
||||
}
|
||||
})
|
||||
.connect({
|
||||
host: server.ipAddress,
|
||||
|
||||
@@ -107,6 +107,24 @@ const connectToServer = async (serverId: string, logPath: string) => {
|
||||
});
|
||||
});
|
||||
})
|
||||
.on("error", (err) => {
|
||||
client.end();
|
||||
if (err.level === "client-authentication") {
|
||||
writeStream.write(
|
||||
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
|
||||
);
|
||||
reject(
|
||||
new Error(
|
||||
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
writeStream.write(
|
||||
`SSH connection error: ${err.message} ${err.level}`,
|
||||
);
|
||||
reject(new Error(`SSH connection error: ${err.message}`));
|
||||
}
|
||||
})
|
||||
.connect({
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
|
||||
Reference in New Issue
Block a user