0

在我的 ApplicationController 中,我有

rescue_from StorageExceptions::AuthorizationFailed, :with => handle_auth_error

def handle_auth_error
  redirect_to error_path(403)
end

但代码没有捕捉到这个错误。我检查了被捕获的是带有消息的 NameError:“未捕获的 throw `StorageExceptions::AuthorizationFailed'”

为什么会这样,我怎样才能捕捉到实际的错误?

4

1 回答 1

0

我也无法rescue_from ..., :with => ...在我的 Rails (2.3.8) 应用程序中使用语法 - 我通过使用替代rescue_from ... do ... end形式解决了它:

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

我从来不明白为什么第一种形式从来没有用过,虽然......

希望这可以帮助!

于 2011-02-07T19:34:08.930 回答