Skip to content

Conversation

steebchen
Copy link
Member

Summary

  • Enhances error logging for JSON parsing failures in Anthropic and Chat API endpoints
  • Adds detailed contextual information to logs including request ID, headers, and error details
  • Improves observability and debugging of invalid JSON request bodies and provider error responses

Changes

Anthropic API

  • Added structured logging for JSON parsing errors in /v1/messages endpoint
  • Logs include request ID, error message, content type, user agent, and referer headers
  • Throws HTTP 400 with detailed error message on invalid JSON

Chat API

  • Added detailed error logging for JSON parsing failures in chat completions endpoint
  • Logs include request ID, error message, content type, user agent, and referer headers
  • Enhanced logging for failures to parse provider error responses at multiple stages
  • Logs include provider, model, HTTP status, status text, parse error details, and response preview
  • Returns structured error responses with detailed messages on invalid JSON

Test plan

  • Verified JSON parsing errors trigger detailed logs with contextual information
  • Confirmed HTTP 400 responses are returned with appropriate error messages on invalid JSON
  • Tested error response parsing failures are logged with relevant metadata
  • Ensured no regressions in normal request handling and error propagation

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/ffe4f3be-2011-4a6b-8915-f717b5afcf07

- Add detailed error context for request JSON parsing failures
- Include request ID, error message, content-type, user-agent, referer in logs
- Enhanced provider error response parsing with context logging
- Better debugging info for "Unexpected non-whitespace character" errors
- Updated both /v1/messages (Anthropic) and /v1/chat/completions routes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terragon/improve-json-error-logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot changed the title Improve JSON error logging in Anthropic and Chat APIs feat(api): improve JSON error logging Sep 18, 2025
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.

1 participant