{"record":{"id":"33e648ae5e3bd071","repo":"can1357/oh-my-pi","slug":"context-response-status-response-statuste","errorCode":null,"errorMessage":"${context}: ${response.status} ${response.statusText}${suffix}","messagePattern":"\\$\\{context\\}: \\$\\{response\\.status\\} \\$\\{response\\.statusText\\}\\$\\{suffix\\}","errorType":"http","errorClass":"SmitheryConnectError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/mcp/smithery-connect.ts","lineNumber":58,"sourceCode":"\tnextCursor?: string | null;\n};\n\nfunction buildAuthHeaders(apiKey: string): Headers {\n\tconst headers = new Headers();\n\theaders.set(\"Authorization\", `Bearer ${apiKey}`);\n\theaders.set(\"Content-Type\", \"application/json\");\n\treturn headers;\n}\n\nfunction toApiUrl(path: string): string {\n\treturn `${SMITHERY_API_BASE_URL}${path}`;\n}\n\nasync function expectOk(response: Response, context: string): Promise<void> {\n\tif (response.ok) return;\n\tconst responseText = await response.text().catch(() => \"\");\n\tconst suffix = responseText ? `: ${responseText}` : \"\";\n\tthrow new SmitheryConnectError(`${context}: ${response.status} ${response.statusText}${suffix}`, response.status);\n}\n\nexport function getSmitheryApiBaseUrl(): string {\n\treturn SMITHERY_API_BASE_URL;\n}\n\nexport async function listSmitheryNamespaces(apiKey: string): Promise<SmitheryNamespace[]> {\n\tconst response = await fetch(toApiUrl(\"/namespaces\"), {\n\t\theaders: buildAuthHeaders(apiKey),\n\t\tsignal: withTimeoutSignal(SMITHERY_CONNECT_TIMEOUT_MS),\n\t});\n\tawait expectOk(response, \"Failed to list Smithery namespaces\");\n\tconst payload = (await response.json()) as SmitheryNamespacesResponse;\n\treturn payload.namespaces ?? [];\n}\n\nexport async function createSmitheryNamespace(apiKey: string): Promise<SmitheryNamespace> {\n\tconst response = await fetch(toApiUrl(\"/namespaces\"), {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/mcp/smithery-connect.ts#L40-L76","documentation":"SmitheryConnectError thrown by the expectOk helper whenever any Smithery Connect API call (namespace or connection CRUD) returns a non-OK response. The message carries the caller-provided context string, HTTP status, statusText, and up to the full response body, so it identifies both which operation failed and why the server rejected it.","triggerScenarios":"Any of listSmitheryNamespaces, createSmitheryNamespace, listSmitheryConnectionsByUrl, createSmitheryConnection, getSmitheryConnection, or deleteSmitheryConnection receiving 4xx/5xx — e.g. 401 for missing/invalid API key, 404 for unknown connection/namespace id, 409 for duplicate creation, 422 for invalid payload.","commonSituations":"Expired or wrong Smithery API key in the auth file (401), referencing a deleted connection by URL (404), creating a namespace that already exists (409), malformed request body (400/422).","solutions":["Read the context and response body in the message — 401/403 means fix the API key, 404 means the resource doesn't exist","Refresh the Smithery API key via login or the dashboard if you got 401","For 404, list existing connections/namespaces first to get a valid id/URL","For 409/422, correct the payload or check for an existing resource before creating"],"exampleFix":"// before: assuming the connection exists\nconst conn = await getSmitheryConnection(url);\n// after: handle 404 by creating instead\ntry {\n  conn = await getSmitheryConnection(url);\n} catch (e) {\n  if (e instanceof SmitheryConnectError && e.status === 404) conn = await createSmitheryConnection(url);\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"// validate inputs the API would reject with 4xx\nif (!connUrl.startsWith(\"https://\")) throw new Error(\"Connection URL must be https\");\nif (!apiKey?.trim()) throw new Error(\"Smithery API key required before Connect API calls\");","typeGuard":"function isSmitheryConnectError(err: unknown): err is SmitheryConnectError {\n  return err instanceof SmitheryConnectError && typeof err.status === \"number\";\n}","tryCatchPattern":"try {\n  await createSmitheryNamespace(name);\n} catch (err) {\n  if (isSmitheryConnectError(err)) {\n    if (err.status === 401) await reauthenticateSmithery();\n    else if (err.status === 409) logger.info(\"Namespace already exists\");\n    else throw err;\n  } else throw err;\n}","preventionTips":["Check the response body included in the message — it carries the server's reason","Handle 401 by refreshing credentials before surfacing the error","Look up existing resources (list*) before create* calls to avoid 409/404","Validate URL/namespace formats client-side to prevent 422s"],"tags":["http","smithery","api","rest"],"backgroundTag":"http-api-error","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}