Skip to content

Commit 4ea6bae

Browse files
committed
Detect Instagram ratelimiting in more places.
1 parent 3117969 commit 4ea6bae

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

app.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,15 @@
474474
}
475475
}
476476
)
477+
next "ratelimited" if response.code == 401 && response.body.include?('"Please wait a few minutes before you try again."')
477478
raise(App::InstagramError, response) if !response.success? || !response.json?
478479
data = response.json["data"]["xdt_api__v1__fbsearch__topsearch_connection"]["users"].find { |data| data["user"]["username"] == name }
479480
next "Error: Could not find an Instagram user with that username. Please enter the username exactly." if !data
480481
user = data["user"]
481482
"#{user["id"]}/#{user["username"]}"
482483
end
483484
return [422, "Something went wrong. Try again later."] if path.nil?
485+
return [429, "Ratelimited. Try again later."] if path == "ratelimited"
484486
return [422, path] if path.start_with?("Error:")
485487
end
486488
redirect Addressable::URI.new(path: "/instagram/#{path}").normalize.to_s, 301

app/services/instagram.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def self.get_post(id)
3232
}
3333
}
3434
)
35+
next nil if response.code == 401 && response.body.include?('"Please wait a few minutes before you try again."')
3536
raise(InstagramError, response) if !response.success? || !response.json
3637

3738
data = response.json["data"]["xdt_shortcode_media"]

0 commit comments

Comments
 (0)