{"record":{"id":"66363da36f324775","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"tag-path-http-resp-status-detail","errorCode":null,"errorMessage":"${TAG} ${path} HTTP ${resp.status}${detail ? `: ${detail.slice(0, 200)}` : \"\"}","messagePattern":"(.+?) (.+?) HTTP (.+?)(.+?)` : \"\"\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"MemoryProxy/src/meta/client.ts","lineNumber":553,"sourceCode":"      resp = await this.fetcher(url, {\n        method: \"POST\",\n        headers,\n        body: JSON.stringify(body),\n        signal: AbortSignal.timeout(this.defaultTimeoutMs),\n      });\n    } catch (err) {\n      throw new Error(`${TAG} ${path} fetch failed: ${(err as Error).message}`);\n    }\n\n    if (!resp.ok) {\n      let detail = \"\";\n      try {\n        detail = await resp.text();\n      } catch { /* ignore */ }\n      console.log(\n        `[wb-debug] metadata-client req path=${path} status=${resp.status} url=${url} serviceId=${this.serviceId} userKey.len=${this.userKey?.length ?? 0} userKey.prefix=${(this.userKey ?? \"\").slice(0, 20)} serviceToken.len=${this.serviceToken?.length ?? 0} body.len=${detail.length} body.head=${detail.slice(0, 300)}`,\n      );\n      throw new Error(`${TAG} ${path} HTTP ${resp.status}${detail ? `: ${detail.slice(0, 200)}` : \"\"}`);\n    }\n\n    const env = (await resp.json()) as CoreEnvelope<T>;\n\n    if (env.code !== 0) {\n      throw new Error(`${TAG} ${path} envelope error ${env.code}: ${env.message ?? \"\"}`);\n    }\n\n    if (env.data === null || env.data === undefined) {\n      throw new Error(`${TAG} ${path} unexpected null data`);\n    }\n\n    return env.data as T;\n  }\n}\n\n// ── Singleton + test injection ──────────────────────────────────────────────\n","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryProxy/src/meta/client.ts#L535-L571","documentation":"MetaClient.fetch throws this when the metadata service responds with a non-2xx HTTP status. The message includes path, status code, and up to 200 chars of the response body as detail, so it carries the server's own error explanation. This is the 'server rejected the request' error, distinct from transport failures and envelope-level business errors.","triggerScenarios":"createTask/updateTask/appendParticipationLog receives resp.ok === false — e.g. 401/403 for bad userKey/serviceToken, 404 wrong path, 400 malformed body, 5xx service error. The [wb-debug] console log prints full request context before throwing.","commonSituations":"Expired or wrong service token / user key (401/403); API version path changed; sending a body the service's schema rejects (400); rate limiting at the gateway (429).","solutions":["Read the detail/status in the message (and the [wb-debug] log line) to identify the exact rejection reason","For 401/403, refresh serviceToken and verify userKey/serviceId configuration","For 400, validate the payload against the service schema before calling","For 5xx/429, retry with exponential backoff; check service health dashboards"],"exampleFix":"// before\nawait client.createTask({ title }); // 403: bad token\n// after\nawait ensureTokenValid(); // refresh serviceToken before metadata calls\nawait client.createTask({ title });","handlingStrategy":"try-catch","validationCode":"// pre-validate auth inputs before the call\nif (!userKey || !serviceToken) throw new Error(\"missing userKey/serviceToken for metadata client\");","typeGuard":"function isHttpError(e: unknown): e is Error & { path: string; status: number } {\n  const m = e instanceof Error && /HTTP \\d{3}/.exec(e.message);\n  return !!m;\n}","tryCatchPattern":"try {\n  await client.updateTask(id, patch);\n} catch (e) {\n  const m = /HTTP (\\d{3})/.exec(e instanceof Error ? e.message : \"\");\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 401 || status === 403) await refreshToken();\n    else if (status >= 500 || status === 429) await backoffRetry();\n    else throw e; // 4xx: do not retry\n  } else throw e;\n}","preventionTips":["Rotate serviceToken before expiry; refresh on 401 automatically","Log the [wb-debug] line on failure — it contains full request context","Validate payload shape client-side to avoid 400s","Apply retry only for 429/5xx, fail fast on other 4xx"],"tags":["http","http-status","metadata","auth"],"backgroundTag":"http-error-response","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}