diff app/models/tweet.rb @ 144:1925b08153dc

Record 404s
author nanaya <me@nanaya.pro>
date Wed, 13 Dec 2017 06:10:13 +0900
parents 8a858aec1905
children c791b6bfeeda
line wrap: on
line diff
--- a/app/models/tweet.rb	Wed Dec 13 06:09:17 2017 +0900
+++ b/app/models/tweet.rb	Wed Dec 13 06:10:13 2017 +0900
@@ -30,18 +30,27 @@
           else
             retry
           end
+        rescue Twitter::Error::NotFound
+          data = { :result => :not_found }
         end
 
-        timeline.select do |tweet|
-          tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
-        end.map do |tweet|
-          # Fails when there's Twitter::NullObject initiated somewhere in previous select
-          # Reference: https://github.com/sferik/twitter/issues/892
-          tweet.to_h
+        data || {
+          :result => :ok,
+          :timeline => timeline.select do |tweet|
+            tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
+          end.map do |tweet|
+            # Fails when there's Twitter::NullObject initiated somewhere in previous select
+            # Reference: https://github.com/sferik/twitter/issues/892
+            tweet.to_h
+          end,
+        }
+      end.tap do |data|
+        raise Twitter::Error::NotFound if data[:result] == :not_found
+
+        data[:timeline_parsed] = data[:timeline].map do |tweet_hash|
+          Twitter::Tweet.new(tweet_hash)
         end
-      end.map do |tweet_hash|
-        Twitter::Tweet.new(tweet_hash)
-      end
+      end[:timeline_parsed]
   end
 
   def user