Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 75dbaf1

Browse files
committed
added a catch for bad ip info
1 parent f54d7df commit 75dbaf1

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

ip_utils/ip_geo.rb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,24 @@
6868
response = RestClient.get(url)
6969
info = JSON.parse(response)
7070

71-
if opt == 'ip'
72-
puts info['query']
73-
elsif opt == 'city'
74-
puts info['city']
75-
elsif opt == 'region'
76-
puts info['region']
77-
elsif opt == 'country'
78-
puts info['country']
79-
elsif opt == 'zip'
80-
puts info['zip']
81-
elsif opt == 'isp'
82-
puts info['isp']
71+
if info['status'] == 'fail'
72+
puts 'No IP info'
8373
else
84-
puts 'Bad input'
74+
if opt == 'ip'
75+
puts info['query']
76+
elsif opt == 'city'
77+
puts info['city']
78+
elsif opt == 'region'
79+
puts info['region']
80+
elsif opt == 'country'
81+
puts info['country']
82+
elsif opt == 'zip'
83+
puts info['zip']
84+
elsif opt == 'isp'
85+
puts info['isp']
86+
else
87+
puts 'Bad input'
88+
end
8589
end
8690
else
8791
puts 'Bad input'

0 commit comments

Comments
 (0)