diff --git a/lib/connection_tester.rb b/lib/connection_tester.rb index 5957b80d5..810a3f2bd 100644 --- a/lib/connection_tester.rb +++ b/lib/connection_tester.rb @@ -129,14 +129,14 @@ class ConnectionTester version, url = ni_urls.max find_software_version(version, http.get(url).body) end - rescue Faraday::ClientError => e - raise HTTPFailure, "#{e.class}: #{e.message}" rescue NodeInfoFailure => e raise e - rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError => e + rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError, Faraday::TimeoutError => e raise NodeInfoFailure, "#{e.class}: #{e.message}" rescue JSON::JSONError => e raise NodeInfoFailure, e.message[0..255].encode(Encoding.default_external, undef: :replace) + rescue Faraday::ClientError => e + raise HTTPFailure, "#{e.class}: #{e.message}" rescue StandardError => e unexpected_error(e) end diff --git a/spec/lib/connection_tester_spec.rb b/spec/lib/connection_tester_spec.rb index 671fec860..a0dce4d4f 100644 --- a/spec/lib/connection_tester_spec.rb +++ b/spec/lib/connection_tester_spec.rb @@ -172,6 +172,14 @@ describe ConnectionTester do expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure) end + it "handles timeout gracefully" do + ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}]} + stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}") + .to_return(status: 200, body: JSON.generate(ni_wellknown)) + stub_request(:get, "#{url}/nodeinfo/1.0").to_raise(Faraday::TimeoutError.new) + expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure) + end + it "handles a invalid jrd document gracefully" do invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}} stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")