Forum: Ruby on Rails custom error pages-- which exceptions to catch?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A095c1664bc2594bf96a7073911d3281?d=identicon&s=25 rafe (Guest)
on 2009-05-21 20:24
(Received via mailing list)
Hi all,

I implemented custom 404 and 500 error pages using rescue_from
according to an example I found at
http://blog.ubrio.us/code/rails-22-custom-error-pa...

Here's my version:

  unless ActionController::Base.consider_all_requests_local
    rescue_from ActiveRecord::RecordNotFound,
ActionController::RoutingError, ActionController::UnknownController,
ActionController::UnknownAction, :with => :render_404
    rescue_from RuntimeError, :with => :render_500
  end

  def render_500
    render :template => "errors/error_500", :layout =>
'singlecolumn', :status => 500
  end

  def render_404
    respond_to do |type|
      type.html { render :template => "errors/error_404", :layout =>
'singlecolumn', :status => 404 }
      type.all  { render :nothing => true, :status => 404 }
    end
    true  # so we can do "render_404 and return"
  end

Then I went to test it, by sticking a call to the undefined name
"foobar" at the top of my homepage action.  This raised a NameError,
which wasn't caught by my 500 error catcher.  Now, I can just add the
error to the list, but I'm curious about other exceptions that could
be raised that I haven't anticipated.  When implementing custom error
pages, which exceptions do folks like to catch?

Rafe Rosen
Common Media, Inc.
http://www.commonmediainc.com
This topic is locked and can not be replied to.