musistudio/claude-code-router · error · Error

${label} failed${payload.message ? `: ${String(payload.messa

Error message

${label} failed${payload.message ? `: ${String(payload.message)}` : ""}.

What it means

assertSuccessfulPayload inspects provider JSON payloads for success === false or code === false and converts them into an Error labeled with the operation (e.g. 'New API refresh'). The provider's message field is appended verbatim, so the underlying cause text comes from the remote API.

Source

Thrown at packages/electron/bundled-plugins/new-api-account/index.cjs:191

    return undefined;
  }
  if (typeof value === "number") {
    if (value <= 0) {
      return undefined;
    }
    const date = new Date(value > 100000000000 ? value : value * 1000);
    return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
  }
  const date = new Date(value);
  return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}

function assertSuccessfulPayload(payload, label) {
  if (!isRecord(payload)) {
    return;
  }
  if (payload.success === false || payload.code === false) {
    throw new Error(`${label} failed${payload.message ? `: ${String(payload.message)}` : ""}.`);
  }
}

function payloadData(payload) {
  return isRecord(payload) && isRecord(payload.data) ? payload.data : payload;
}

function providerBaseUrl(provider) {
  return readString(provider?.api_base_url) || readString(provider?.baseUrl) || readString(provider?.baseurl);
}

function newApiRootBaseUrl(baseUrl) {
  const value = readString(baseUrl);
  if (!value) {
    return "";
  }
  try {
    const url = new URL(providerUrlWithDefaultScheme(value));

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Read the appended provider message — it states the remote failure reason
  2. Fix the root cause (credentials, quota, endpoint) identified by that message
  3. If the provider uses a different failure flag (numeric code), extend assertSuccessfulPayload to interpret it
  4. Retry only for transient messages like rate limiting, with backoff

Example fix

// before
if (payload.success === false || payload.code === false) { throw new Error(`${label} failed...`); }

// after
if (payload.success === false || payload.code === false || Number(payload.code) > 0) {
  throw new Error(`${label} failed: ${String(payload.message ?? payload.code)}.`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try { await call(); } catch (e) {
  if (e instanceof Error && /failed(?! to)/.test(e.message)) {
    const reason = e.message.split(': ')[1] ?? 'provider error';
    handleProviderReason(reason);
  } else throw e;
}

Prevention

When it happens

Trigger: Any New API HTTP call whose body is { success: false, message: '...' } (or code: false) — invalid credentials, insufficient quota, rate limit, bad endpoint — after fetch itself resolved successfully.

Common situations: Wrong API key, expired token, quota exhausted, provider returning soft errors with HTTP 200, or message in a non-English locale/HTML content.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/48fe9780dc41eb02. Report an issue: GitHub.