ActiveRecord::RecordNotFound の dev と prod での振る舞いの違いを掘る
- DebugExceptions
- ExceptionWrapper
-
wrapper.show?
の詳細 -
show_detailed_exceptions
の詳細-
config.consider_all_requests_local
およびHogeController#show_detailed_exceptions?
の影響を受ける
-
- ShowExceptions
-
PublicExceptions
-
config.exceptions_app
で差し替え可能
-
class MyException < StandardError
ActionDispatch::ExceptionWrapper.rescue_responses[name] = :not_found
end
などとすれば、独自 Exception で 500 以外の status_code を返すようになる。また、
config.action_dispatch.show_exceptions = :rescuable
設定の時に request test で例外そのものが飛ばず、ステータスコードのテストができる。
symbol と status code の対応はここらへん
dev 環境で表示される画面を作ってるのはこいつpublic/500.html
とかを表示するが、その制御はこいつ
ここで並んでスタックに積まれる。
DebugExceptions
は RAILS_ENV に関わらず、常に middleware として読み込まれている。 (一部の controller だけで機能させる、のような設定が可能)
PublicExceptions
は config.exceptions_app
で差し替え可能。
DebugExceptions
が render するスイッチは action_dispatch.show_detailed_exceptions
3.2.16 config.consider_all_requests_local
Is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the Rails::Info controller will show the application runtime context in /rails/info/properties. true by default in the development and test environments, and false in production. For finer-grained control, set this to false and implementshow_detailed_exceptions?
in controllers to specify which requests should provide debugging information on errors.
DebugExceptions
でも ShowExceptions
でも、 Exception class -> status code の変換を担うのはここ。
wrapper.show?(request)
の実装はここ