Skip to content

Commit

Permalink
Merge pull request #925 from alphagov/rescue-timeout-errors-from-api
Browse files Browse the repository at this point in the history
Ignore Faraday::TimeoutError exceptions
  • Loading branch information
pixeltrix authored Apr 30, 2024
2 parents 66194c6 + 9211c4b commit 2ab1abb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/constituency/api_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/models/constituency/api_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2ab1abb

Please sign in to comment.