Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Better Errors ignore 404 errors

Rails • Asked by Brian Schwartz

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.

Thanks!


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 ActionController::RoutingError or 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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.