Conversation
The catch-all under the api namespace was `*unmatched`, and a wildcard segment needs at least one character, so the namespace root itself fell through to the HTML 404 page. Making the glob optional turns the route into `/api(/*unmatched)`, which also covers the bare prefix. Adds an integration test for /api, /api/, /api/v1 and /api/nope (GET) and /api (POST); the first two and the POST fail without the change. Fixes rubyforgood#89 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`unmatched_route` was a public method on `Api::BaseController`, so every
API controller inherited it as an action (`Api::V1::TasksController
.action_methods` included it). It now lives on a dedicated
`Api::ErrorsController`, which is the only thing the catch-all route
reaches.
`GET /api/v1/tasks.xml` answered 200 with a JSON body, as if the
extension had been honoured. The tasks resources now carry
`constraints: { format: :json }`: `/tasks` and `/tasks.json` behave as
before, and any other extension (`/tasks.xml`, `/tasks/1.xml`) falls
through to the JSON 404 like any other unknown path.
Tests cover both, and assert the catch-all is no longer an action on
the tasks controller.
Fixes rubyforgood#90
Fixes rubyforgood#91
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What this does
Three small fixes to the JSON 404 handling under the
apinamespace, all in the routing/error seam:/apiand/api/answered with the HTML 404 page. The catch-all was*unmatched, and a wildcard segment needs at least one character, so the namespace root fell through. The glob is now optional (/api(/*unmatched)), which also covers the bare prefix.unmatched_routewas a public method onApi::BaseController, so every API controller inherited it as an action (Api::V1::TasksController.action_methodsincluded it). It now lives on a dedicatedApi::ErrorsController, the only thing the catch-all reaches.GET /api/v1/tasks.xmlanswered 200 with a JSON body, as if the extension had been honoured. The tasks resources now carryconstraints: { format: :json }, so/tasksand/tasks.jsonbehave as before and any other extension falls through to the JSON 404.The mobile app negotiates via the
Acceptheader, not the extension, so it is not affected.Issue
Closes #89
Closes #90
Closes #91
Testing
Integration tests for
/api,/api/,/api/v1,/api/nope(GET) and/api(POST); for/api/v1/tasks.xmland/api/v1/tasks/1.xml; and an assertion thatunmatched_routeis no longer an action on the tasks controller. The/api,/api/and POST cases fail without the first commit; the.xmlones without the second.Ran
bin/rails test(139 runs, 0 failures),bin/rubocopandbin/brakemanclean, andbin/rails routes | grep apito eyeball the result.Written with help from Claude Code; I reviewed and ran everything myself.
🤖 Generated with Claude Code