Skip to content

fix: handle JSON format in render_not_found#2526

Merged
olleolleolle merged 1 commit intomasterfrom
fix/render-not-found-json-error
Mar 18, 2026
Merged

fix: handle JSON format in render_not_found#2526
olleolleolle merged 1 commit intomasterfrom
fix/render-not-found-json-error

Conversation

@mroderick
Copy link
Collaborator

@mroderick mroderick commented Mar 17, 2026

This is a fix for https://app.rollbar.com/a/codebar-production/fix/item/codebar-production/668#detail.

image
ActionView::MissingTemplate: Missing template errors/not_found with {locale: [:en], formats: [:json], variants: [], handlers: [:raw, :erb, :html, :builder, :ruby, :haml]}.

Searched in:
  * "/app/app/views"
  * "/app/vendor/bundle/ruby/3.4.0/gems/turbo-rails-2.0.23/app/views"
  * "/app/vendor/bundle/ruby/3.4.0/gems/actiontext-8.1.2/app/views"
  * "/app/vendor/bundle/ruby/3.4.0/gems/actionmailbox-8.1.2/app/views"

block in ApplicationController#render_not_found(/app/app/controllers/application_controller.rb:33)
    render template: 'errors/not_found', layout: false, status: :not_found
ApplicationController#render_not_found(/app/app/controllers/application_controller.rb:33)
    render template: 'errors/not_found', layout: false, status: :not_found

Summary

  • Fixes MissingTemplate error in production when requests come with JSON format
  • Reverts render_not_found to use respond_to block, matching the pattern in the exception handler

Root Cause

Commit 3eeca62 simplified render_not_found to only render an HTML template, but didn't handle non-HTML formats.

Reverts the render_not_found method to use respond_to, matching the pattern
used in the exception handler. This fixes MissingTemplate errors when
requests come in with JSON format (e.g., from API clients).

The previous change (3eeca62) simplified render_not_found but broke JSON
responses. Now HTML requests get the proper 404 page while API requests
get an empty 404 response.

Adds tests for both HTML and JSON format handling.
@mroderick mroderick marked this pull request as ready for review March 17, 2026 22:05
Copy link
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@olleolleolle olleolleolle merged commit 69012e4 into master Mar 18, 2026
22 of 23 checks passed
@olleolleolle olleolleolle deleted the fix/render-not-found-json-error branch March 18, 2026 07:10
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