Hmbown/CodeWhale · error

${compactRuntimeError(response.status, body)}

Error message

${compactRuntimeError(response.status, body)}

What it means

createRuntimeClient's runtimeJson helper throws whenever the Runtime HTTP response is not ok, formatting the status plus any JSON error body through compactRuntimeError. This is the bridge-core client's unified surface for all Runtime API failures.

Solutions

  1. Read the compacted status/body in the thrown message to identify the specific HTTP failure, and fix the corresponding request (auth, body, path).
  2. Verify the Runtime is running and the bridge's runtime URL/port env vars point at it (curl the endpoint manually).
  3. Re-authenticate or restart the Runtime if the status is 401/403 (stale session or rotated credentials).

Example fix

// before: bridge points at wrong port
RUNTIME_URL=http://127.0.0.1:3000
// after: match the port codewhale web prints
RUNTIME_URL=http://127.0.0.1:8787
Defensive patterns

Strategy: try-catch

Validate before calling

const probe = await fetch(runtimeUrl + '/v1/providers');
if (!probe.ok) throw new Error(`runtime not reachable/healthy: ${probe.status}`);

Type guard

function isRuntimeHttpError(err) {
  return err instanceof Error && /\b[45]\d\d\b/.test(err.message);
}

Try / catch

try {
  body = await runtimeJson('/v1/turns', { method: 'POST', body });
} catch (e) {
  console.error('[bridge] runtime call failed:', e.message); // includes status + body
  return fallbackReply('The assistant backend is unavailable.');
}

Prevention

When it happens

Trigger: Any runtimeJson() call (or bridge using createRuntimeClient) where the Runtime responds 4xx/5xx — auth rejection, unknown route, invalid request body, or Runtime crash handling.

Common situations: Bridge configured against a wrong RUNTIME_URL/port; Runtime not running (connection error surfaces differently) or returning 500 from a bad turn request; stale auth headers after a Runtime restart.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/09361bf4edc22a90. Report an issue: GitHub.

Appendix: source

Thrown at integrations/bridge-core/src/lib.mjs:465

}

export function createRuntimeClient({ runtimeUrl, runtimeToken }) {
  function authHeaders() {
    return { authorization: `Bearer ${runtimeToken}` };
  }

  async function runtimeJson(route, options = {}) {
    const response = await fetch(`${runtimeUrl}${route}`, {
      method: options.method || "GET",
      headers: {
        ...(options.auth === false ? {} : authHeaders()),
        ...(options.body ? { "content-type": "application/json" } : {})
      },
      body: options.body ? JSON.stringify(options.body) : undefined
    });
    const body = await readJsonSafe(response);
    if (!response.ok) {
      throw new Error(compactRuntimeError(response.status, body));
    }
    return body;
  }

  return { runtimeJson, authHeaders };
}

export function compactRuntimeError(status, body) {
  const message =
    body?.error?.message ||
    body?.message ||
    (typeof body === "string" ? body : JSON.stringify(body));
  return `Runtime API request failed (${status}): ${message}`;
}

export function latestRunningTurn(detail) {
  const turns = Array.isArray(detail?.turns) ? detail.turns : [];
  for (let index = turns.length - 1; index >= 0; index -= 1) {

View on GitHub (pinned to 433685b202)