diff options
author | Rhenium <rhenium@rhe.jp> | 2014-01-30 20:24:14 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2014-01-30 20:24:14 +0900 |
commit | 1bbd6763716dfbfbe0f11bc7e0e95e5f0b1a483a (patch) | |
tree | 7246537c2142b3990bc41fa3566578ff42be7a44 /app | |
parent | a1eda75c4788e8c62f3ad8275d40eceb5cc49d28 (diff) | |
download | aclog-1bbd6763716dfbfbe0f11bc7e0e95e5f0b1a483a.tar.gz |
catch error when exception raised in Favorite/Retweet.from_json
Diffstat (limited to 'app')
-rw-r--r-- | app/models/favorite.rb | 11 | ||||
-rw-r--r-- | app/models/retweet.rb | 11 |
2 files changed, 10 insertions, 12 deletions
diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 6e3d197..892efff 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -14,12 +14,11 @@ class Favorite < ActiveRecord::Base tweet = Tweet.from_json(json[:target_object]) user = User.from_json(json[:source]) favorite = Favorite.new(tweet: tweet, user: user) - if favorite.save - logger.debug("Successfully created a favorite: #{favorite.id}") - else - logger.debug("Failed to create a favorite: #{favorite}") - end - + favorite.save! + logger.debug("Successfully created a favorite: #{favorite.id}") + rescue + logger.debug("Failed to create a favorite: #{favorite}") + ensure favorite end end diff --git a/app/models/retweet.rb b/app/models/retweet.rb index 4b6f65e..7b83dba 100644 --- a/app/models/retweet.rb +++ b/app/models/retweet.rb @@ -14,12 +14,11 @@ class Retweet < ActiveRecord::Base tweet = Tweet.from_json(json[:retweeted_status]) user = User.from_json(json[:user]) retweet = Retweet.new(id: json[:id], tweet: tweet, user: user) - if retweet.save - logger.debug("Successfully created a retweet: #{retweet.id}") - else - logger.debug("Failed to create a retweet: #{retweet}") - end - + retweet.save! + logger.debug("Successfully created a retweet: #{retweet.id}") + rescue + logger.debug("Failed to create a retweet: #{retweet}") + ensure retweet end end |