From 494dffc7b206963ce11766643d9f1e960e5b1213 Mon Sep 17 00:00:00 2001 From: Sergiy Kukunin Date: Sat, 27 Jul 2019 15:23:01 +0300 Subject: [PATCH] Don't swallow exceptions While it's arguably for rescuing timeouts, it's wrong to swallow all exceptions. For example, I spent about an hour figuring out why webmock doesn't work for zester, while it worked everywhere else. By default, webmock disables all http requests, and raises exceptions with suggestion to mock it. But in case with zester, it returned just `Web services are currently unavailable`, which was really weird: webmock seemed not working and API call was made, but Zillow returned an error about unavailability. After all I had to debug to this method. If exceptions were not swallowed, it was clear where the problem is. --- lib/zester/resource.rb | 6 +----- spec/zester/resource_spec.rb | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/zester/resource.rb b/lib/zester/resource.rb index 2bcf757..845735e 100644 --- a/lib/zester/resource.rb +++ b/lib/zester/resource.rb @@ -8,11 +8,7 @@ def initialize(client) end def get_results(endpoint, resource_type, params = {}) - begin - Response.new(self.client.perform_get(endpoint, params), resource_type) - rescue Timeout::Error, Exception - Response.new({resource_type => {:message => {:code => "3", :text => "Web services are currently unavailable"}}}, resource_type) - end + Response.new(self.client.perform_get(endpoint, params), resource_type) end end diff --git a/spec/zester/resource_spec.rb b/spec/zester/resource_spec.rb index ada171d..9ff2d59 100644 --- a/spec/zester/resource_spec.rb +++ b/spec/zester/resource_spec.rb @@ -26,13 +26,9 @@ VCR.turn_on! end - it "should rescue a timeout error" do + it "should not rescue a timeout error" do stub_request(:get, "http://www.zillow.com/webservice/GetRateSummary.htm?zws-id=#{ZWS_ID}").to_timeout - response = resource.get_results('GetRateSummary', :rate_summary) - response.success?.should be_false - response.message.should_not be_nil - response.message.code.should == "3" - response.response_code.should == 3 + expect {get_response}.to raise_error(Timeout::Error) end end