From e3e7a69ebc49aade68d09c50552937d03409c7b9 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Tue, 16 Jul 2024 18:54:34 +0800 Subject: [PATCH] handle ip.sb return 520 --- src/cli.cr | 2 +- src/myip.cr | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cli.cr b/src/cli.cr index 7ba4ee0..0b28572 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -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) %} diff --git a/src/myip.cr b/src/myip.cr index 6269db0..7691dbf 100644 --- a/src/myip.cr +++ b/src/myip.cr @@ -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