Skip to content

Commit

Permalink
Add a grace period experiment.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Aug 28, 2021
1 parent 542fb3c commit 4b3d484
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,11 @@
end
"#{user["id"] || user["pk"]}/#{user["username"]}"
rescue App::InstagramRatelimitError
"Error: Instagram is ratelimited. For more information, see https://github.com/stefansundin/rssbox/issues/39"
"ratelimited"
end
return [422, "Something went wrong. Try again later."] if path.nil?
return [422, path] if path.start_with?("Error:")
return [429, "Error: Instagram is ratelimited. For more information, see https://github.com/stefansundin/rssbox/issues/39"] if path == "ratelimited"
end
redirect Addressable::URI.new(path: "/instagram/#{path}").normalize.to_s, 301
end
Expand Down Expand Up @@ -635,11 +636,21 @@
}
end.to_json
rescue App::InstagramRatelimitError
"Error: Instagram is ratelimited. For more information, see https://github.com/stefansundin/rssbox/issues/39"
"ratelimited"
end
return [422, "Something went wrong. Try again later."] if data.nil?
return [422, data] if data.start_with?("Error:")

if data == "ratelimited"
if Time.now < @updated_at+300
# To make it easier to subscribe to Instagram feeds, there is a grace period for 5 minutes where an empty feed is returned.
# Note that you have to manually construct the feed URL yourself.
data = "[]"
else
return [429, "Error: Instagram is ratelimited. For more information, see https://github.com/stefansundin/rssbox/issues/39"]
end
end

@data = JSON.parse(data)

type = %w[videos photos].pick(params[:type]) || "posts"
Expand Down
2 changes: 1 addition & 1 deletion app/instagram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ def self.get_post(id)

error App::InstagramRatelimitError do |e|
status 429
"There are too many requests going to Instagram right now. Someone is probably abusing this service. PLEASE SLOW DOWN!"
"Instagram is ratelimited. For more information, see https://github.com/stefansundin/rssbox/issues/39"
end

0 comments on commit 4b3d484

Please sign in to comment.