fix: json catching

This commit is contained in:
cpacker
2026-02-28 23:04:56 -08:00
parent f65a23d092
commit ac4621d91d

View File

@@ -176,15 +176,27 @@ export async function runListenSubcommand(argv: string[]): Promise<number> {
}); });
if (!registerResponse.ok) { if (!registerResponse.ok) {
const error = (await registerResponse.json()) as { message?: string }; let errorMessage = `Registration failed (HTTP ${registerResponse.status})`;
console.error(`Registration failed: ${error.message || "Unknown error"}`); try {
const error = (await registerResponse.json()) as { message?: string };
if (error.message) errorMessage = error.message;
} catch {
const text = await registerResponse.text().catch(() => "");
if (text) errorMessage += `: ${text.slice(0, 200)}`;
}
console.error(errorMessage);
return 1; return 1;
} }
const { connectionId, wsUrl } = (await registerResponse.json()) as { let registerBody: { connectionId: string; wsUrl: string };
connectionId: string; try {
wsUrl: string; registerBody = (await registerResponse.json()) as typeof registerBody;
}; } catch {
throw new Error(
"Registration endpoint returned non-JSON response — is the server running?",
);
}
const { connectionId, wsUrl } = registerBody;
if (debugMode) { if (debugMode) {
console.log(`[${formatTimestamp()}] Registered successfully`); console.log(`[${formatTimestamp()}] Registered successfully`);