fix: show why SSH connection tests and runs fail (#7)
Test connection, key installation and runs now tell authentication failures apart from unreachable hosts (refused, timeout, DNS, ...) instead of a generic "SSH connection failed". The web client keeps the server's deliberate error messages (4xx, 502, 503) and shows them in the hosts page; unexpected 500 errors still show only the status. The reload hint appears only on 409 conflicts.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { HttpError, json } from "../api";
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
it("keeps the server's error message and status", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({ statusCode: 502, error: "Bad Gateway", message: "SSH authentication failed: check the user and the saved password or key" }), { status: 502, headers: { "Content-Type": "application/json" } })));
|
||||
const error = (await json("/x").catch((e: HttpError) => e)) as HttpError;
|
||||
expect(error).toBeInstanceOf(HttpError);
|
||||
expect(error.status).toBe(502);
|
||||
expect(error.message).toBe("SSH authentication failed: check the user and the saved password or key");
|
||||
});
|
||||
it("falls back to the status when the body is not JSON", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async () => new Response("<html>", { status: 500 })));
|
||||
expect(((await json("/x").catch((e: HttpError) => e)) as HttpError).message).toBe("Request failed (500)");
|
||||
});
|
||||
it("does not surface messages of unexpected server errors", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({ statusCode: 500, message: "EACCES: permission denied, open '/var/lib/shellbook/x'" }), { status: 500 })));
|
||||
expect(((await json("/x").catch((e: HttpError) => e)) as HttpError).message).toBe("Request failed (500)");
|
||||
});
|
||||
Reference in New Issue
Block a user