Skip to content

Commit

Permalink
Check the content-type header to try to avoid some JSON parsing error…
Browse files Browse the repository at this point in the history
…s from occurring.
  • Loading branch information
stefansundin committed Jul 5, 2020
1 parent 882bc6b commit f1c44a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
response = Instagram.get("/graphql/query/", options)
return [401, "The sessionid expired!"] if params.has_key?(:sessionid) && response.code == 302
return [response.code, "Instagram user does not exist."] if !response.json["data"]["user"]
raise(InstagramError, response) if !response.success? || !response.json
raise(InstagramError, response) if !response.success? || !response.json?

@data = response.json["data"]["user"]
@user = CGI.unescape(username)
Expand Down
4 changes: 4 additions & 0 deletions lib/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def body
@response.body
end

def json?
@response["content-type"].start_with?("application/json")
end

def json
@json ||= JSON.parse(@response.body)
end
Expand Down

0 comments on commit f1c44a1

Please sign in to comment.