Better Errors ignore 404 errors
I'm using better_errors gem to track errors better. Any idea how to make it ignore 404 or ActiveRecord::RecordNotFound exceptions? I want to test to make sure my 404 page is working correctly and I'm seeing better errors screens instead.
I think it's always going to thrown an exception in development because that's internal to Rails. You can navigate to
/404 to see your 404 page and Rails will catch any
ActiveRecord::RecordNotFound and render the 404 when in production mode.
I guess you could either run in production mode locally (the real true test) or you could rescue_from those exceptions. Something like so:
rescue_from ActiveRecord::RecordNotFound, :with => :rescue404 rescue_from ActionController::RoutingError, :with => :rescue404 def test_404 render file: 'public/404.html', status: :not_found, layout: false end
I guess that works (testing 404 manually). I'm intentionally throwing a
ActiveRecord::RecordNotFound when a page in my app is visited but not published yet. So I wanted to make sure it was throwing it. I'm getting the
Better_Errors error page with that exception, so I guess it's working.
Yeah, not much better way to test it that I know of unfortunately. As long as you're throwing that exception, you shouldn't have any problems.