Remove more uses of rescue nil.

This commit is contained in:
Guo Xiang Tan
2018-05-07 11:38:04 +08:00
parent 77eb93ffb7
commit 0d74c30fa7
2 changed files with 16 additions and 3 deletions

View File

@ -66,7 +66,12 @@ after_initialize do
# ensure no race condition when poll is automatically closed
if poll["close"].present?
close_date = Time.zone.parse(poll["close"]) rescue nil
close_date =
begin
close_date = Time.zone.parse(poll["close"])
rescue ArgumentError
end
raise StandardError.new I18n.t("poll.poll_must_be_open_to_vote") if close_date && close_date <= Time.zone.now
end
@ -159,7 +164,12 @@ after_initialize do
Jobs.cancel_scheduled_job(:close_poll, post_id: post.id, poll_name: name)
if poll["status"] == "open" && poll["close"].present?
close_date = Time.zone.parse(poll["close"]) rescue nil
close_date =
begin
Time.zone.parse(poll["close"])
rescue ArgumentError
end
Jobs.enqueue_at(close_date, :close_poll, post_id: post.id, poll_name: name) if close_date && close_date > Time.zone.now
end
end