Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/controllers/idv/in_person/usps_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def index
else
response = proofer.request_pilot_facilities
end
rescue => err
Rails.logger.warn(err)
rescue => error
Rails.logger.warn(
{
error_name: error.class.name,
message: error.message,
source: self.class.name,
}.to_json,
Comment on lines +31 to +35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add a descriptive key/event name so we can have something to find these by (not sure it's the best name, but the general idea)

Suggested change
{
error_name: error.class.name,
message: error.message,
source: self.class.name,
}.to_json,
{
warning: "UspsLocationsController#index argcis"
error_name: error.class.name,
message: error.message,
source: self.class.name,
}.to_json,

)
response = proofer.request_pilot_facilities
end

Expand Down
14 changes: 11 additions & 3 deletions spec/controllers/idv/in_person/usps_locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,22 @@

context 'with unsuccessful fetch' do
let(:exception) { Faraday::ConnectionFailed }
let(:message) { 'Something happened' }

before do
allow(proofer).to receive(:request_facilities).with(fake_address).and_raise(exception)
allow(proofer).to receive(:request_facilities).with(fake_address).
and_raise(exception.new(message))
allow(proofer).to receive(:request_pilot_facilities).and_return(pilot_locations)
end

it 'returns all pilot locations' do
expect(Rails.logger).to receive(:warn)
it 'logs an informative error and returns all pilot locations' do
logged_error = {
error_name: exception.name,
message: message,
source: described_class.name,
}.to_json

expect(Rails.logger).to receive(:warn).with(logged_error)
response = post :index,
params: { address: { street_address: '742 Evergreen Terrace',
city: 'Springfield',
Expand Down