From 019534794c2d9338171c3cc5dd26e255ee78034f Mon Sep 17 00:00:00 2001 From: Felipe <41008398+StrawberryMaster@users.noreply.github.com> Date: Sun, 9 Feb 2025 16:24:02 +0000 Subject: [PATCH] Taking care of empty responses fixes "unexpected token at ''" appearing after fetching a list of snapshots --- lib/wayback_machine_downloader/archive_api.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/wayback_machine_downloader/archive_api.rb b/lib/wayback_machine_downloader/archive_api.rb index 6861ac3..45eb799 100644 --- a/lib/wayback_machine_downloader/archive_api.rb +++ b/lib/wayback_machine_downloader/archive_api.rb @@ -10,7 +10,9 @@ module ArchiveAPI begin response = http.get(request_url) - json = JSON.parse(response.body) + body = response.body.to_s.strip + return [] if body.empty? + json = JSON.parse(body) # Check if the response contains the header ["timestamp", "original"] json.shift if json.first == ["timestamp", "original"]