Skip to content

Conversation

@slimee
Copy link

@slimee slimee commented Dec 3, 2025

Summary

  • Fix exception handling in forest_admin_rpc_agent package to return JSON error responses instead of HTML
  • Add rescue StandardError block in register_rails method to catch exceptions
  • Add handle_rails_exception method that uses ErrorTranslator to format errors as JSON
  • Add test to verify 404 errors return proper JSON response with correct headers

Problem

When exceptions are raised in RPC agent routes (like NotFoundError for non-existent collections or resources), they were not caught and Rails would return HTML error pages instead of JSON.

Solution

Similar to how forest_admin_rails handles exceptions in its ForestController, the RPC agent now:

  1. Catches all StandardError exceptions in the route handler
  2. Uses ErrorTranslator to convert them to HTTP exceptions
  3. Returns properly formatted JSON responses with:
    • Correct HTTP status code (e.g., 404)
    • Content-Type: application/json header
    • Custom headers (e.g., x-error-type: object-not-found)
    • Error details in standardized format

Test plan

  • Add test for NotFoundError returning JSON 404 response
  • Run existing test suite to ensure no regressions
  • Manually test with a Rails app using RPC agent

🤖 Generated with Claude Code

…tions

When exceptions are raised in RPC agent routes (like NotFoundError),
they were not caught and Rails would return HTML error pages. This fix
adds exception handling in register_rails to catch all exceptions and
return properly formatted JSON error responses with correct HTTP status
codes and headers.

Changes:
- Add rescue block in register_rails to catch StandardError
- Add handle_rails_exception method to translate exceptions to JSON responses
- Add test to verify 404 errors return JSON instead of HTML

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

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

qltysh bot commented Dec 3, 2025

All good ✅
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more.

Refactor register_rails method to comply with RuboCop metrics:
- Extract request handling logic into handle_rails_request method to reduce method length
- Remove redundant begin block in proc
- Fix unused block argument warnings in specs

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

Co-Authored-By: Claude <[email protected]>
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