{"record":{"id":"445a57e807522ca4","repo":"Hmbown/CodeWhale","slug":"runtime-api-request-failed-response-status-for-method-path","errorCode":null,"errorMessage":"Runtime API request failed (${response.status}) for ${method} ${path}","messagePattern":"Runtime API request failed \\((.+?)\\) for (.+?) (.+?)","errorType":"exception","errorClass":"RuntimeApiError","httpStatus":null,"severity":"error","filePath":"npm/runtime-sdk/index.js","lineNumber":191,"sourceCode":"      headers.set(\"content-type\", \"application/json\");\n      init.body = JSON.stringify(options.body);\n    }\n\n    const response = await this.fetchImpl(new URL(path, this.baseUrl), init);\n    if (response.ok) {\n      return response;\n    }\n\n    const body = await readErrorBody(response);\n    const errorOptions = { status: response.status, method, path, body };\n    if (options.capability && [404, 405, 501].includes(response.status)) {\n      throw new RuntimeCapabilityError(\n        options.capability,\n        `Runtime API capability '${options.capability}' is not available at ${method} ${path}`,\n        errorOptions,\n      );\n    }\n    throw new RuntimeApiError(\n      `Runtime API request failed (${response.status}) for ${method} ${path}`,\n      errorOptions,\n    );\n  }\n}\n\nexport function createRuntimeClient(options = {}) {\n  return new CodeWhaleRuntimeClient(options);\n}\n\nfunction normalizeBaseUrl(value) {\n  return value.endsWith(\"/\") ? value : `${value}/`;\n}\n\nfunction segment(value) {\n  if (value === null || value === undefined || String(value).trim() === \"\") {\n    throw new TypeError(\"Runtime API path segment must be a non-empty value\");\n  }","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/npm/runtime-sdk/index.js#L173-L209","documentation":"#rawRequest()'s fallback: when the runtime returns a non-OK status that is not a capability mismatch (i.e. not 404/405/501 with a declared capability), it throws RuntimeApiError including the status, method, and path. The error options carry the response body for diagnosis. It covers auth failures, bad requests, conflicts, and 5xx from the runtime.","triggerScenarios":"401/403 from missing or invalid auth credentials; 400 from a malformed request built by your code; 409 conflicts; 500/502/503 from the runtime process or an upstream proxy.","commonSituations":"Expired or wrong API token; request body shape changed between SDK versions; runtime crashed or is being restarted behind a load balancer returning 502.","solutions":["Read err.status and err.body from the RuntimeApiError to identify the exact server complaint.","For 401/403, fix the auth token/credentials supplied to the client.","For 5xx, retry with backoff and check runtime logs/health endpoint.","Ensure SDK and runtime versions are compatible."],"exampleFix":"// before\nawait client.getFleetRun(id);\n// after\ntry {\n  await client.getFleetRun(id);\n} catch (err) {\n  if (err instanceof RuntimeApiError && err.status === 503) return retryWithBackoff();\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await call(); } catch (err) { if (err instanceof RuntimeApiError) { if (err.status === 429 || err.status >= 500) return retry(err); if (err.status === 401 || err.status === 403) return reauth(); } throw err; }","preventionTips":["Always log err.status and err.body from RuntimeApiError for diagnosis.","Refresh auth tokens before expiry; validate credentials at client construction.","Add retry-with-backoff for 5xx/429 and circuit-break repeated 4xx."],"tags":["http","api-error","runtime-api","status-code"],"backgroundTag":"http-error-response","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}