我调用gemurl_for
的methodaws-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
最佳答案
捕捉错误时请更具体:
begin
# code that get the error
rescue AWS::Errors::MissingCredentialsError => e
# code that handles the exception
end