(null);
// ref allows us to avoid a memory leak
const mountedRef = useRef(false);
@@ -77,12 +78,18 @@ function InPersonLocationPostOfficeSearchStep({ onChange, toPreviousStep, regist
return (
<>
+ {uspsError && (
+
+ {t('idv.failure.exceptions.internal_error')}
+
+ )}
{t('in_person_proofing.headings.po_search.location')}
{t('in_person_proofing.body.location.po_search.po_search_about')}
{locationResults && foundAddress && (
{
await findByText('{"selected_location":"Baltimore"}');
});
-
- it('allows search by address when enabled', async () => {
- const { findByText, findByLabelText } = render(
-
-
- ,
- );
-
- await userEvent.type(
- await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'),
- '100 main',
- );
- await userEvent.click(
- await findByText('in_person_proofing.body.location.po_search.search_button'),
- );
- await findByText('in_person_proofing.body.location.po_search.results_description');
- });
-
- it('validates input and shows inline error', async () => {
- const { findByText } = render(
-
-
- ,
- );
-
- await userEvent.click(
- await findByText('in_person_proofing.body.location.po_search.search_button'),
- );
-
- await findByText('in_person_proofing.body.location.inline_error');
- });
-
- it('displays no post office results if a successful search is followed by an unsuccessful search', async () => {
- const { findByText, findByLabelText, queryByRole } = render(
-
-
- ,
- );
-
- await userEvent.type(
- await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'),
- '594 Broadway New York',
- );
- await userEvent.click(
- await findByText('in_person_proofing.body.location.po_search.search_button'),
- );
-
- await userEvent.type(
- await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'),
- 'asdfkf',
- );
- await userEvent.click(
- await findByText('in_person_proofing.body.location.po_search.search_button'),
- );
-
- const results = queryByRole('status', {
- name: 'in_person_proofing.body.location.po_search.results_description',
- });
- expect(results).not.to.exist();
- });
});
diff --git a/app/javascript/packages/request/index.ts b/app/javascript/packages/request/index.ts
index b7854df46cb..927a71def66 100644
--- a/app/javascript/packages/request/index.ts
+++ b/app/javascript/packages/request/index.ts
@@ -41,5 +41,9 @@ export async function request(
}
const response = await window.fetch(url, { ...fetchOptions, headers, body });
- return json ? response.json() : response.text();
+ if (response.ok) {
+ return json ? response.json() : response.text();
+ }
+
+ throw new Error(await response.json());
}
diff --git a/app/services/analytics_events.rb b/app/services/analytics_events.rb
index 9dc13a15d25..0fd82711eab 100644
--- a/app/services/analytics_events.rb
+++ b/app/services/analytics_events.rb
@@ -2978,6 +2978,31 @@ def user_registration_email_confirmation(
)
end
+ # Tracks if request to get USPS in-person proofing locations fails
+ # @param [String] exception_class
+ # @param [String] exception_message
+ # @param [Boolean] response_body_present
+ # @param [Hash] response_body
+ # @param [Integer] response_status_code
+ def idv_in_person_locations_request_failure(
+ exception_class:,
+ exception_message:,
+ response_body_present:,
+ response_body:,
+ response_status_code:,
+ **extra
+ )
+ track_event(
+ 'Request USPS IPP locations: request failed',
+ exception_class: exception_class,
+ exception_message: exception_message,
+ response_body_present: response_body_present,
+ response_body: response_body,
+ response_status_code: response_status_code,
+ **extra,
+ )
+ end
+
# Tracks when USPS in-person proofing enrollment is created
# @param [String] enrollment_code
# @param [Integer] enrollment_id
diff --git a/package.json b/package.json
index 62ecc844f87..d3da7a50078 100644
--- a/package.json
+++ b/package.json
@@ -81,6 +81,7 @@
"sinon-chai": "^3.7.0",
"stylelint": "^14.13.0",
"svgo": "^2.8.0",
+ "swr": "^2.0.0",
"typescript": "^4.8.4",
"webpack-dev-server": "^4.11.1",
"whatwg-fetch": "^3.4.0"
diff --git a/spec/controllers/idv/in_person/usps_locations_controller_spec.rb b/spec/controllers/idv/in_person/usps_locations_controller_spec.rb
index 4382f76307d..5ae3e124c80 100644
--- a/spec/controllers/idv/in_person/usps_locations_controller_spec.rb
+++ b/spec/controllers/idv/in_person/usps_locations_controller_spec.rb
@@ -103,18 +103,21 @@
context 'with arcgis search enabled' do
context 'with a nil address in params' do
+ let(:param_error) { ActionController::ParameterMissing.new(param: address) }
+
before do
- allow(proofer).to receive(:request_pilot_facilities).and_return(pilot_locations)
+ allow(proofer).to receive(:request_facilities).with(address).and_raise(param_error)
end
subject(:response) do
post :index, params: { address: nil }
end
- it 'returns the pilot locations' do
+ it 'returns no locations' do
+ subject
json = response.body
facilities = JSON.parse(json)
- expect(facilities.length).to eq 4
+ expect(facilities.length).to eq 0
end
end
@@ -130,24 +133,58 @@
end
end
- context 'with unsuccessful fetch' do
- let(:exception) { Faraday::ConnectionFailed }
+ context 'with a timeout from Faraday' do
+ let(:timeout_error) { Faraday::TimeoutError.new }
+
+ before do
+ allow(proofer).to receive(:request_facilities).with(address).and_raise(timeout_error)
+ end
+
+ it 'returns an internal server error' do
+ subject
+ expect(@analytics).to have_logged_event(
+ 'Request USPS IPP locations: request failed',
+ exception_class: timeout_error.class,
+ exception_message: timeout_error.message,
+ response_body_present:
+ timeout_error.response_body.present?,
+ response_body: timeout_error.response_body,
+ response_status_code: timeout_error.response_status,
+ )
+
+ status = response.status
+ expect(status).to eq 500
+ end
+ end
+
+ context 'with failed connection to Faraday' do
+ let(:exception) { Faraday::ConnectionFailed.new }
+ subject(:response) do
+ post :index,
+ params: { address: { street_address: '742 Evergreen Terrace',
+ city: 'Springfield',
+ state: 'MO',
+ zip_code: '89011' } }
+ end
before do
allow(proofer).to receive(:request_facilities).with(fake_address).and_raise(exception)
- allow(proofer).to receive(:request_pilot_facilities).and_return(pilot_locations)
end
- it 'returns all pilot locations' do
- expect(Rails.logger).to receive(:warn)
- response = post :index,
- params: { address: { street_address: '742 Evergreen Terrace',
- city: 'Springfield',
- state: 'MO',
- zip_code: '89011' } }
- json = response.body
- facilities = JSON.parse(json)
- expect(facilities.length).to eq 4
+ it 'returns no locations' do
+ subject
+ expect(@analytics).to have_logged_event(
+ 'Request USPS IPP locations: request failed',
+ exception_class: exception.class,
+ exception_message: exception.message,
+ response_body_present:
+ exception.response_body.present?,
+ response_body: exception.response_body,
+ response_status_code: exception.response_status,
+ )
+
+ facilities = JSON.parse(response.body)
+ expect(facilities.length).to eq 0
end
end
end