Skip to content

Commit

Permalink
handle ip.sb return 520
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Jul 16, 2024
1 parent 59d7340 commit e3e7a69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ myip.ip_from_ib_sb
myip.ip_from_ip111
myip.process

spinner.stop("Done")
spinner.success("successful!".colorize(:yellow).on_blue.bold.to_s)

at_exit do
{% if flag?(:win32) %}
Expand Down
5 changes: 4 additions & 1 deletion src/myip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class Myip
spawn do
url = "https://api.ip.sb/geoip"
response = HTTP::Client.get(url)
result = JSON.parse(response.body)
body = response.body
result = JSON.parse(body)
io = IO::Memory.new
PrettyPrint.format(result, io, width: 79)
io.rewind
chan.send({"#{url}:您访问外网地址信息:", io.gets_to_end, nil})
rescue JSON::ParseException
chan.send({"#{url}", body.not_nil!, nil})
rescue ex : ArgumentError | Socket::Error
chan.send({"#{url}", ex.message.not_nil!, nil})
end
Expand Down

0 comments on commit e3e7a69

Please sign in to comment.