Has anyone had luck overriding "config.consider_all_requests_local" in dev mode, with a custom "def local_request?"

:rescue_worker_s_helmet: rying to create a conditional override for rails error output (suitable for certain situations where you would speed up feedback/review loop from a divided review group – one that should see error messages, and one that has no use for them)

Working with Rails 7.2.2.1

The global override “config.consider_all_requests_local” does work for me, in config/environments/development.rb - I can switch off the error messages in dev mode by setting that to “false”

But seeking granular, runtime control – googling suggests to define/override the

“def local_request?” method. Suggestions include adding the method to ActionController::Rescue

I have tried to do that in application.rb and under initializers/my_custom_inits.rb

Has no effect – rails is still honoring the “config.consider_all_requests_local = false” flag

I have tried the following in various startup scopes:

ActionController::Rescue.module_eval do

def local_request?
  true # set to true for testing (later have runtime conditionals)
end

end

Not overriding the (overriding) config flag (essentially – seeking to override the override, conditionally)

Did a workaround

reversed the logical booleans by routing “/404”, “/500”, etc, in routes.rb to various actions of errors_controller:

get “/404”, :to => “errors#not_found”

get “/500”, :to => “errors#internal_error”

… etc…

Inside the errors_controller actions I have the “$!” variable for error message and backtrace.

$!.message $!.backtrace

Can conditionally show them, based on whatever. Achieved the desired control… my original question is now just for sport/ academic discussion

fyi, the logic is:

request.env["action_dispatch.show_detailed_exceptions"] ||= show_detailed_exceptions?

So if you wanted to override it conditionally, you would set config.consider_all_requests_local = false in your config (because that gets assigned to the rack request env) and then define a dynamic ApplicationController#show_detailed_exceptions? method. … or just assign the rack request env in a before_action.

aha, it was already documented here: Configuring Rails Applications — Ruby on Rails Guides