mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 19:32:27 +00:00
fix(daemon): surface probe close reasons (#56282)
Merged via squash.
Prepared head SHA: c356980aa4
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
This commit is contained in:
@@ -92,6 +92,26 @@ describe("probeGatewayStatus", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers the close reason over a generic timeout when both are present", async () => {
|
||||
callGatewayMock.mockReset();
|
||||
probeGatewayMock.mockReset();
|
||||
probeGatewayMock.mockResolvedValueOnce({
|
||||
ok: false,
|
||||
error: "timeout",
|
||||
close: { code: 1008, reason: "pairing required" },
|
||||
});
|
||||
|
||||
const result = await probeGatewayStatus({
|
||||
url: "ws://127.0.0.1:19191",
|
||||
timeoutMs: 5_000,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: "gateway closed (1008): pairing required",
|
||||
});
|
||||
});
|
||||
|
||||
it("surfaces status RPC errors when requireRpc is enabled", async () => {
|
||||
callGatewayMock.mockReset();
|
||||
probeGatewayMock.mockReset();
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
import { withProgress } from "../progress.js";
|
||||
|
||||
function resolveProbeFailureMessage(result: {
|
||||
error?: string | null;
|
||||
close?: { code: number; reason: string } | null;
|
||||
}): string {
|
||||
const closeHint = result.close
|
||||
? `gateway closed (${result.close.code}): ${result.close.reason}`
|
||||
: null;
|
||||
if (closeHint && (!result.error || result.error === "timeout")) {
|
||||
return closeHint;
|
||||
}
|
||||
return result.error ?? closeHint ?? "gateway probe failed";
|
||||
}
|
||||
|
||||
export async function probeGatewayStatus(opts: {
|
||||
url: string;
|
||||
token?: string;
|
||||
@@ -47,12 +60,9 @@ export async function probeGatewayStatus(opts: {
|
||||
if (result.ok) {
|
||||
return { ok: true } as const;
|
||||
}
|
||||
const closeHint = result.close
|
||||
? `gateway closed (${result.close.code}): ${result.close.reason}`
|
||||
: null;
|
||||
return {
|
||||
ok: false,
|
||||
error: result.error ?? closeHint ?? "gateway probe failed",
|
||||
error: resolveProbeFailureMessage(result),
|
||||
} as const;
|
||||
} catch (err) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user