Why doesn't rails 2.1 catch exceptions with rescue_from?

335 Views Asked by At

in my ApplicationController, I have

rescue_from StorageExceptions::AuthorizationFailed, :with => handle_auth_error

def handle_auth_error
  redirect_to error_path(403)
end

but the code is not catching this error. I have checked that what is being caught is NameError with message: "uncaught throw `StorageExceptions::AuthorizationFailed'"

Why is this and how can I catch the actual error?

1

There are 1 best solutions below

0
On

I had trouble getting the rescue_from ..., :with => ... syntax working in my Rails (2.3.8) app, too - I solved it by using the alternative rescue_from ... do ... end form:

rescue_from(ActionController::InvalidAuthenticityToken) do |e|
    #TODO: Flash something?
    logger.error "! Invalid authenticity token when accessing #{request.url}"
    render(:template => 'sessions/new', :layout => 'pre_login')
end

I never figured out why the first form never worked, though...

Hope this helps!