Skip to content
This repository was archived by the owner on Jul 25, 2025. It is now read-only.

Commit 28ce354

Browse files
Shpigfordclaude
andcommitted
Handle JSON format requests in error responses
- Add proper format handling to RedirectsController#catch_all - Explicitly handle JSON format in ApplicationController#not_found - Return 404 status without template for non-HTML requests - Fixes errors for requests like .well-known/assetlinks.json 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ce2cd0a commit 28ce354

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def not_found
2525
render file: Rails.root.join("public", "404.html"), status: :not_found, layout: false
2626
end
2727
end
28+
format.json { head :not_found }
2829
format.any { head :not_found }
2930
end
3031
end

app/controllers/redirects_controller.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ def catch_all
88
destination = redirect_rule.process_destination(request.path)
99
redirect_to destination, status: redirect_rule.status_code
1010
else
11-
if Rails.env.production? || Rails.env.development?
12-
render "errors/not_found", status: :not_found
13-
else
14-
render file: Rails.root.join("public", "404.html"), status: :not_found, layout: false
11+
respond_to do |format|
12+
format.html do
13+
if Rails.env.production? || Rails.env.development?
14+
render "errors/not_found", status: :not_found
15+
else
16+
render file: Rails.root.join("public", "404.html"), status: :not_found, layout: false
17+
end
18+
end
19+
format.json { head :not_found }
20+
format.any { head :not_found }
1521
end
1622
end
1723
end

0 commit comments

Comments
 (0)