diff --git a/app/models/constituency/api_query.rb b/app/models/constituency/api_query.rb index 85672829d..080a6297d 100644 --- a/app/models/constituency/api_query.rb +++ b/app/models/constituency/api_query.rb @@ -13,6 +13,16 @@ class ApiQuery MP_START = './StartDate' MP_END = './EndDate' + IGNORE_EXCEPTIONS = [ + Faraday::ResourceNotFound, + Faraday::ClientError, + Faraday::TimeoutError + ] + + NOTIFY_EXCEPTIONS = [ + Faraday::Error + ] + def fetch(postcode) response = client.call(postcode) @@ -21,9 +31,9 @@ def fetch(postcode) else [] end - rescue Faraday::ResourceNotFound, Faraday::ClientError => e + rescue *IGNORE_EXCEPTIONS => e return [] - rescue Faraday::Error => e + rescue *NOTIFY_EXCEPTIONS => e Appsignal.send_exception(e) return [] end diff --git a/spec/models/constituency/api_query_spec.rb b/spec/models/constituency/api_query_spec.rb index 8b4cbc680..9fd247cae 100644 --- a/spec/models/constituency/api_query_spec.rb +++ b/spec/models/constituency/api_query_spec.rb @@ -110,6 +110,7 @@ def constituency(external_id, name, ons_code, mp_id = nil, mp_name = nil, mp_dat end it "returns an empty array" do + expect(Appsignal).not_to receive(:send_exception) expect(query.fetch("N1")).to eq([]) end end @@ -120,6 +121,7 @@ def constituency(external_id, name, ons_code, mp_id = nil, mp_name = nil, mp_dat end it "returns an empty array" do + expect(Appsignal).not_to receive(:send_exception) expect(query.fetch("N1")).to eq([]) end end @@ -130,6 +132,7 @@ def constituency(external_id, name, ons_code, mp_id = nil, mp_name = nil, mp_dat end it "returns an empty array" do + expect(Appsignal).not_to receive(:send_exception) expect(query.fetch("N1")).to eq([]) end end @@ -140,6 +143,7 @@ def constituency(external_id, name, ons_code, mp_id = nil, mp_name = nil, mp_dat end it "returns an empty array" do + expect(Appsignal).not_to receive(:send_exception) expect(query.fetch("N1")).to eq([]) end end @@ -150,6 +154,7 @@ def constituency(external_id, name, ons_code, mp_id = nil, mp_name = nil, mp_dat end it "returns an empty array" do + expect(Appsignal).to receive(:send_exception) expect(query.fetch("N1")).to eq([]) end end