diegosouzapw/OmniRoute · error

${await errorMessage(res)}

Error message

${await errorMessage(res)}

What it means

Shared requestJson helper for the agent-bridge maintenance API: a fetch returned a non-ok response and the sanitized server error message (or fallback status text) is rethrown to the calling route client.

Solutions

  1. Inspect the embedded server message to identify which maintenance endpoint failed
  2. Retry idempotent operations (diagnose, fetch config); do not retry mutations blindly
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/inspector/agentBridgeMaintenanceApi.ts:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/0bea8569196d7bbc. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/inspector/agentBridgeMaintenanceApi.ts:31

 * never pulls their DB dependencies.
 */
import type { DiagnosticReport } from "@/mitm/inspector/diagnostics";
import type { AgentBridgeConfig, ImportResult } from "@/lib/inspector/configPortability";

export interface DiagnoseResult extends DiagnosticReport {
  /** The port the diagnose route probed (echoed back for display). */
  port: number;
}

/** Extract the sanitized server error message, falling back to the status. */
async function errorMessage(res: Response): Promise<string> {
  const body = (await res.json().catch(() => null)) as { error?: { message?: string } } | null;
  return body?.error?.message ?? `HTTP ${res.status}`;
}

async function requestJson<T>(url: string, init?: RequestInit): Promise<T> {
  const res = await fetch(url, init);
  if (!res.ok) throw new Error(await errorMessage(res));
  return (await res.json()) as T;
}

/** Run the capture-pipeline self-test (server/cert/dns reachability). */
export function runDiagnose(agentId?: string): Promise<DiagnoseResult> {
  const url = agentId
    ? `/api/tools/agent-bridge/diagnose?agentId=${encodeURIComponent(agentId)}`
    : "/api/tools/agent-bridge/diagnose";
  return requestJson<DiagnoseResult>(url);
}

/** Untrust + remove the MITM root CA from the OS store (explicit, idempotent). */
export function removeCaCert(sudoPassword?: string): Promise<{ trusted: boolean }> {
  return requestJson<{ ok: boolean; trusted: boolean }>("/api/tools/agent-bridge/cert", {
    method: "DELETE",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(sudoPassword ? { sudoPassword } : {}),
  });

View on GitHub (pinned to a179ffed5b)