简体   繁体   English

为什么Rails 2.1不能使用result_from捕获异常?

[英]Why doesn't rails 2.1 catch exceptions with rescue_from?

in my ApplicationController, I have 在我的ApplicationController中,我有

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'" 我检查了被捕获的是NameError,并显示了消息:“未抛出throw StorageExceptions :: AuthorizationFailed”

Why is this and how can I catch the actual error? 为什么会这样,如何捕获实际错误?

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 ..., :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

I never figured out why the first form never worked, though... 我从来没有想过为什么第一种形式没用过,但是...

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM