Skip to content

managed-chatkit: normalize upstream error payloads to readable strings - #130

Open
shuofengzhang wants to merge 1 commit into
openai:mainfrom
shuofengzhang:fix-managed-chatkit-error-message-shape
Open

managed-chatkit: normalize upstream error payloads to readable strings#130
shuofengzhang wants to merge 1 commit into
openai:mainfrom
shuofengzhang:fix-managed-chatkit-error-message-shape

Conversation

@shuofengzhang

Copy link
Copy Markdown

What changed

  • Added resolve_error_message(...) in managed-chatkit/backend/app/main.py to normalize upstream error payloads into a readable string.
  • Updated /api/create-session error handling to use this resolver instead of directly forwarding payload["error"].
  • Added regression tests in managed-chatkit/backend/tests/test_main.py covering:
    • nested upstream error objects ({"error": {"message": ...}})
    • plain string errors ({"error": "..."})
    • endpoint behavior ensuring JSON response always returns a string error field.

Why

The OpenAI-style error shape is typically nested (for example, {"error": {"message": "..."}}).
Previously, the backend forwarded payload["error"] directly, which could return an object instead of a string.

That makes frontend/debug output inconsistent and can produce low-signal error displays (for example object rendering instead of a clear message).

Practical gain / Why this matters

  • Immediate user-facing reliability improvement: /api/create-session now consistently returns a human-readable string error.
  • Lower debugging friction: integrators see precise failure messages from upstream rather than opaque object payloads.
  • Maintainer safety: the change is tightly scoped to error-message extraction and keeps status codes/cookie behavior unchanged.

Insight / Why this matters

  • Root cause: upstream API errors are often structured objects, but previous code assumed error was already a string.
  • Why easy to miss: success paths and simple error paths work; object-shaped errors appear only in specific failure responses.
  • Tradeoff: this intentionally prefers readable message extraction over forwarding full raw error objects in this endpoint.
  • Impact: avoids ambiguous client error rendering and improves operational clarity during integration failures.

Testing

  • cd managed-chatkit/backend && source .venv/bin/activate && pytest -q
    • 3 passed
  • cd managed-chatkit/backend && source .venv/bin/activate && python -m ruff check app tests
  • cd managed-chatkit/backend && source .venv/bin/activate && python -m ruff format --check app tests
  • cd managed-chatkit/backend && source .venv/bin/activate && python -m mypy app --ignore-missing-imports

@m74278803-cmyk m74278803-cmyk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shuofengzhang:fix-managed-chatkit-error-message-shape

@m74278803-cmyk m74278803-cmyk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shuofengzhang:fix-managed-chatkit-error-message-shape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants