HKUDS/nanobot · error · RuntimeError
Mochat API error: (code= )
Error message
Mochat API error: {msg} (code={parsed_dict['code']}) What it means
Raised by Mochat _post_json when the 2xx JSON body carries a non-zero integer code — the Mochat API convention signals application-level failure inside a successful HTTP response; the message and code are surfaced to the caller.
Solutions
- Fix the request per the embedded API error message (often auth or invalid session)
- Retry transient application errors after a short delay
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at nanobot/channels/mochat/runtime.py:973 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26).
Data as JSON: /api/errors/4c18b801a9ad8674.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/channels/mochat/runtime.py:973
response = await self._http.post(url, headers={
"Content-Type": "application/json", "X-Claw-Token": self.config.claw_token,
}, json=payload)
if not response.is_success:
raise RuntimeError(f"Mochat HTTP {response.status_code}: {response.text[:200]}")
try:
parsed = response.json()
except Exception:
parsed = response.text
if isinstance(parsed, dict):
parsed_dict = cast(dict[str, Any], parsed)
if isinstance(parsed_dict.get("code"), int):
if parsed_dict["code"] != 200:
msg = str(
parsed_dict.get("message")
or parsed_dict.get("name")
or "request failed"
)
raise RuntimeError(
f"Mochat API error: {msg} (code={parsed_dict['code']})"
)
data = parsed_dict.get("data")
return cast(dict[str, Any], data) if isinstance(data, dict) else {}
return parsed_dict
return {}
async def _api_send(self, path: str, id_key: str, id_val: str,
content: str, reply_to: str | None, group_id: str | None = None) -> dict[str, Any]:
"""Unified send helper for session and panel messages."""
body: dict[str, Any] = {id_key: id_val, "content": content}
if reply_to:
body["replyTo"] = reply_to
if group_id:
body["groupId"] = group_id
return await self._post_json(path, body)
@staticmethodView on GitHub (pinned to 42f37dc4c0)