【发布时间】:2018-08-12 14:15:33
【问题描述】:
我有一份工作,其 run 方法如下所示:
def perform(share, document)
@history = document.scheduled_posts.find_by(provider: share[:provider])
job = ProviderJob.new(document, share)
begin
job.run
@history.update_columns(response: 'posted', status: 'complete')
rescue StandardError => e
@history.update_columns(response: e.message, status: 'error')
raise Errors::FailedJob, e.message
rescue FbGraph2::Exception::Unauthorized, Twitter::Error::Unauthorized, Mailchimp::UserUnknownError, LinkedIn::OAuthError, Errors::MissingAuth => e
@history.update_columns(response: e.message, status: 'unauthorised')
raise Errors::FailedJob, e.message
end
end
即使Errors::MissingAuth 被引发,StandardError 块也会捕获它,因为它继承自它。如何确保正确的块捕获指定的异常?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5