From 007e22a34f595b4d99da8af1f44d7e2697ede475 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 2 Jul 2023 09:49:17 +1000 Subject: [PATCH] Guard against network issues --- lib/adamantium/client/omdb.rb | 2 ++ lib/adamantium/syndication/raindrop.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/adamantium/client/omdb.rb b/lib/adamantium/client/omdb.rb index 970da32..0d830fe 100644 --- a/lib/adamantium/client/omdb.rb +++ b/lib/adamantium/client/omdb.rb @@ -9,6 +9,8 @@ module Adamantium def call(imdb_id:) @client.find_by_id(imdb_id) + rescue + nil end end end diff --git a/lib/adamantium/syndication/raindrop.rb b/lib/adamantium/syndication/raindrop.rb index 89e5e66..08c8155 100644 --- a/lib/adamantium/syndication/raindrop.rb +++ b/lib/adamantium/syndication/raindrop.rb @@ -11,7 +11,7 @@ module Adamantium end def call(post:) - uri = URI('https://api.raindrop.io/rest/v1/raindrop') + uri = URI("https://api.raindrop.io/rest/v1/raindrop") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true @@ -21,14 +21,20 @@ module Adamantium "link" => post[:url] } body = JSON.dump(dict) - req = Net::HTTP::Post.new(uri) + req = Net::HTTP::Post.new(uri) req.add_field "Authorization", api_key req.add_field "Content-Type", "application/json; charset=utf-8" req.body = body - response = http.request(req) + response = nil - if response.code.to_s == "200" + begin + response = http.request(req) + rescue + # NOOP + end + + if response && response.code.to_s == "200" Success() else Failure(:failed_to_post_to_raindrop)