{"record":{"id":"453591c236bf3315","repo":"musistudio/claude-code-router","slug":"sample-headers-must-be-a-json-object-containing-st","errorCode":null,"errorMessage":"Sample headers must be a JSON object containing string or string-array values","messagePattern":"Sample headers must be a JSON object containing string or string-array values","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/pages/home/shared/routing.ts","lineNumber":194,"sourceCode":"export function normalizeRouteScriptSampleRequest(value: unknown): RouteScriptSampleRequest {\n  if (!isPlainRecord(value) || !isPlainRecord(value.body)) {\n    throw new Error(\"Sample must be a JSON object with an object body\");\n  }\n  const headers = normalizeRouteScriptSampleHeaders(value.headers);\n  return {\n    body: value.body,\n    headers,\n    ...(typeof value.method === \"string\" ? { method: value.method } : {}),\n    ...(typeof value.sessionId === \"string\" ? { sessionId: value.sessionId } : {}),\n    ...(typeof value.tokenCount === \"number\" ? { tokenCount: value.tokenCount } : {}),\n    ...(typeof value.url === \"string\" ? { url: value.url } : {})\n  };\n}\n\nfunction normalizeRouteScriptSampleHeaders(value: unknown): Record<string, string | string[]> {\n  if (value === undefined) return {};\n  if (!isPlainRecord(value)) {\n    throw new Error(\"Sample headers must be a JSON object containing string or string-array values\");\n  }\n  const headers: Record<string, string | string[]> = {};\n  for (const [name, headerValue] of Object.entries(value)) {\n    if (typeof headerValue === \"string\") {\n      headers[name] = headerValue;\n      continue;\n    }\n    if (Array.isArray(headerValue) && headerValue.every((entry) => typeof entry === \"string\")) {\n      headers[name] = headerValue;\n      continue;\n    }\n    throw new Error(\"Sample headers must be a JSON object containing string or string-array values\");\n  }\n  return headers;\n}\n\nexport function normalizeRouterRuleCondition(value: unknown): RouterRuleCondition | undefined {\n  if (!isPlainRecord(value)) {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/ui/src/pages/home/shared/routing.ts#L176-L212","documentation":"Thrown by normalizeRouteScriptSampleHeaders while validating the `headers` field of a route script sample request. When headers are provided they must be a plain JSON object; anything else (array, string, null, number) fails normalization with this error.","triggerScenarios":"Passing headers as a string (e.g. \"Content-Type: application/json\"), an array of [name, value] pairs, null, or a URLSearchParams object instead of a plain object keyed by header name.","commonSituations":"Copy-pasting a curl-style header string instead of splitting it into an object; serializing headers before submission; leaving headers explicitly set to null rather than undefined.","solutions":["Provide headers as a plain object of string or string[] values, e.g. { \"Content-Type\": \"application/json\" }","Omit the headers field entirely (undefined returns {})","Set null-valued headers to undefined or remove them"],"exampleFix":"// before\n{ body: {}, headers: \"Accept: application/json\" }\n\n// after\n{ body: {}, headers: { \"Accept\": \"application/json\" } }","handlingStrategy":"type-guard","validationCode":"const h = sample.headers;\nif (h !== undefined && (typeof h !== \"object\" || h === null || Array.isArray(h))) { /* fix or drop headers */ }","typeGuard":"function isHeadersObject(v: unknown): v is Record<string, string | string[]> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try { normalizeRouteScriptSampleHeaders(headers); } catch (e) { if (e instanceof Error && e.message.includes(\"Sample headers\")) { headers = {}; } else throw e; }","preventionTips":["Build headers with a parser (e.g. Object.fromEntries) instead of pasting strings","Omit headers entirely when there are none","Never set headers to null; use undefined"],"tags":["validation","headers","json","routing"],"backgroundTag":"request-payload-validation-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}