{"record":{"id":"48fe9780dc41eb02","repo":"musistudio/claude-code-router","slug":"label-failed-payload-message-string-pay","errorCode":null,"errorMessage":"${label} failed${payload.message ? `: ${String(payload.message)}` : \"\"}.","messagePattern":"(.+?) failed(.+?)` : \"\"\\}\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron/bundled-plugins/new-api-account/index.cjs","lineNumber":191,"sourceCode":"    return undefined;\n  }\n  if (typeof value === \"number\") {\n    if (value <= 0) {\n      return undefined;\n    }\n    const date = new Date(value > 100000000000 ? value : value * 1000);\n    return Number.isNaN(date.getTime()) ? undefined : date.toISOString();\n  }\n  const date = new Date(value);\n  return Number.isNaN(date.getTime()) ? undefined : date.toISOString();\n}\n\nfunction assertSuccessfulPayload(payload, label) {\n  if (!isRecord(payload)) {\n    return;\n  }\n  if (payload.success === false || payload.code === false) {\n    throw new Error(`${label} failed${payload.message ? `: ${String(payload.message)}` : \"\"}.`);\n  }\n}\n\nfunction payloadData(payload) {\n  return isRecord(payload) && isRecord(payload.data) ? payload.data : payload;\n}\n\nfunction providerBaseUrl(provider) {\n  return readString(provider?.api_base_url) || readString(provider?.baseUrl) || readString(provider?.baseurl);\n}\n\nfunction newApiRootBaseUrl(baseUrl) {\n  const value = readString(baseUrl);\n  if (!value) {\n    return \"\";\n  }\n  try {\n    const url = new URL(providerUrlWithDefaultScheme(value));","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/bundled-plugins/new-api-account/index.cjs#L173-L209","documentation":"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.","triggerScenarios":"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.","commonSituations":"Wrong API key, expired token, quota exhausted, provider returning soft errors with HTTP 200, or message in a non-English locale/HTML content.","solutions":["Read the appended provider message — it states the remote failure reason","Fix the root cause (credentials, quota, endpoint) identified by that message","If the provider uses a different failure flag (numeric code), extend assertSuccessfulPayload to interpret it","Retry only for transient messages like rate limiting, with backoff"],"exampleFix":"// before\nif (payload.success === false || payload.code === false) { throw new Error(`${label} failed...`); }\n\n// after\nif (payload.success === false || payload.code === false || Number(payload.code) > 0) {\n  throw new Error(`${label} failed: ${String(payload.message ?? payload.code)}.`);\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { await call(); } catch (e) {\n  if (e instanceof Error && /failed(?! to)/.test(e.message)) {\n    const reason = e.message.split(': ')[1] ?? 'provider error';\n    handleProviderReason(reason);\n  } else throw e;\n}","preventionTips":["Surface the embedded provider message to users verbatim","Distinguish auth vs quota vs rate-limit reasons for retry policy","Don't retry non-idempotent calls on soft failures"],"tags":["provider-response","api-error","error-mapping"],"backgroundTag":"api-returned-error-payload","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}