From 71dbbcb26658afa5639164538711bf54a3056a2b Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 5 Sep 2019 07:47:02 -0400 Subject: [PATCH] Add error handling for pulling monitors --- src/instances.cr | 17 ++++++++++------- src/instances/views/index.ecr | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/instances.cr b/src/instances.cr index 07fbca5..21685dc 100644 --- a/src/instances.cr +++ b/src/instances.cr @@ -35,16 +35,19 @@ spawn do loop do begin response = JSON.parse(HTTP::Client.get(URI.parse("https://uptime.invidio.us/api/getMonitorList/89VnzSKAn?page=#{page}")).body) + + monitors += response["psp"]["monitors"].as_a + page += 1 + + if response["psp"]["perPage"].as_i * page > response["psp"]["totalMonitors"].as_i + break + end rescue ex + error_message = response.try &.["errorStats"]? + error_message ||= ex.message + puts "Exception pulling monitors: #{error_message}" next end - - monitors += response["psp"]["monitors"].as_a - page += 1 - - if response["psp"]["perPage"].as_i * page > response["psp"]["totalMonitors"].as_i - break - end end body = HTTP::Client.get(URI.parse("https://raw.githubusercontent.com/wiki/omarroth/invidious/Invidious-Instances.md")).body diff --git a/src/instances/views/index.ecr b/src/instances/views/index.ecr index bdf7c41..6754f51 100644 --- a/src/instances/views/index.ecr +++ b/src/instances/views/index.ecr @@ -4,7 +4,7 @@ - + Invidious Instances