我正在调用gem url_for
的方法aws-s3
,并抛出MissingCredentialsError < StandardError
。如何从调用url_for
的班级中拯救它?我知道缺少凭据问题的解决方案,但我想知道如何处理异常。试过这个,没有运气:
begin
... code that get the error...
rescue MissingCredentialsError
a = "THIS IS AN ERROR"
end
当我运行我的测试时,它会碰到这个错误:
ActionView::Template::Error: uninitialized constant Receipt::MissingCredentialsError
答案 0 :(得分:3)
捕获错误时更具体:
begin
# code that get the error
rescue AWS::Errors::MissingCredentialsError => e
# code that handles the exception
end