Skip to content

Commit

Permalink
Add custom error for Instagram 429 errors.. In the week, I have start…
Browse files Browse the repository at this point in the history
…ed seeing tens of thousands of these errors per day. There is obviously a moron abusing the service right now. I will start blocking IPs real soon.
  • Loading branch information
stefansundin committed Jul 12, 2019
1 parent 34c49be commit 7a0b085
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/instagram.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class InstagramError < HTTPError; end
class InstagramRatelimitError < HTTPError; end
class InstagramTokenError < InstagramError; end

class Instagram < HTTP
Expand Down Expand Up @@ -29,6 +30,9 @@ def self.get(url, options={headers: {}}, tokens={csrftoken: nil})
if response.code == 403
raise(InstagramTokenError, response)
end
if response.code == 429
raise(InstagramRatelimitError)
end
response
end

Expand Down Expand Up @@ -62,3 +66,8 @@ def self.get_post(id, opts={}, tokens={})
status 503
"There was a problem talking to Instagram. Please try again in a moment."
end

error InstagramRatelimitError do |e|
status 429
"There are too many requests going to Instagram right now. Someone is probably abusing this service. PLEASE SLOW DOWN!"
end
2 changes: 1 addition & 1 deletion lib/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def redirect_same_origin?
end

class HTTPError < StandardError
def initialize(obj)
def initialize(obj=nil)
@obj = obj
end

Expand Down

0 comments on commit 7a0b085

Please sign in to comment.