fix(rpc-agent): return JSON error responses instead of HTML for exceptions#219
Open
fix(rpc-agent): return JSON error responses instead of HTML for exceptions#219
Conversation
…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 <noreply@anthropic.com>
|
All good ✅ |
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 <noreply@anthropic.com>
Add explicit begin/rescue block in the handler proc to ensure proper exception handling. This should fix the test failures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
… test Fix variable naming in mock that was causing test failures: - Change **options to **opts to avoid unused variable warning - Remove unused &_block parameter This should fix the test "returns a JSON error response with 404 status" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1630374 to
3065150
Compare
The mock was not capturing the handler proc correctly because it was using **opts instead of explicit keyword arguments. Changed to explicitly capture defaults:, to:, via:, as:, and route_alias: to match the actual router.match call signature. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3065150 to
76c3011
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
forest_admin_rpc_agentpackage to return JSON error responses instead of HTMLrescue StandardErrorblock inregister_railsmethod to catch exceptionshandle_rails_exceptionmethod that usesErrorTranslatorto format errors as JSONProblem
When exceptions are raised in RPC agent routes (like
NotFoundErrorfor 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_railshandles exceptions in itsForestController, the RPC agent now:StandardErrorexceptions in the route handlerErrorTranslatorto convert them to HTTP exceptionsTest plan
🤖 Generated with Claude Code