Rescue_from for javascript requests

Viewed 1810

In my Rails 2.3.8 application I had a rescue_from code for exceptions, which are thrown during javascript actions:

rescue_from ::Exception, :with => :show_js_errors

...

def show_js_errors exception
  if request.format == :js
    flash[:error] = 'some error occured'
    render :update do |page|
      page.redirect_to({:controller => '/home', :action => :index})
    end
  else
    # use default error handling for non-JS requests
    rescue_action_without_handler(exception)
  end
end

So my users get an error message, if an ajax call runs into an error. In Rails 3, I can't simply call the default error handling, because the "without_handler" method doesn't exist any more.

update doh

I posted this after 3 hours of searching, but only 30 minutes after posting I found a solution myself.

Just re-raise the exception.

Since you are in the error handling, no further handling is done with this exception.

1 Answers
Related