Skip to content

LG-7241: Handle errors when creating USPS enrollment#6629

Merged
sheldon-b merged 45 commits intomainfrom
sbachstein/lg-6872-add-error-handling
Aug 15, 2022
Merged

LG-7241: Handle errors when creating USPS enrollment#6629
sheldon-b merged 45 commits intomainfrom
sbachstein/lg-6872-add-error-handling

Conversation

@sheldon-b
Copy link
Contributor

@sheldon-b sheldon-b commented Jul 26, 2022

📋 Changes

  • Adds error handling to the fsm v1 and fsm v2 flows so that if the call to create an enrollment in the USPS API fails the error is logged, the user is shown an error message, and the user can try again
  • Adds mock behavior for simulating errors from the USPS API:
    • Timeout
    • Client error
    • Server error
    • Invalid response (missing enrollment code)

📺 Demo

FSM v1 password confirm page

Note: when the user encounters this error the page is reloaded and their password is cleared from the form

fsm-v1

FSM v2 password confirm page

fsm-v2

Client error log example

{"name":"USPS IPPaaS enrollment failed","properties":{"event_properties":{"context":"authentication","enrollment_id":17,"exception_class":"UspsInPersonProofing::Exception::RequestEnrollException","exception_message":"Sponsor for sponsorID 5 not found","reason":"Request exception","original_exception_class":"Faraday::BadRequestError"},"new_event":false,"new_session_path":false,"new_session_success_state":false,"success_state":"PUT|/verify/review|USPS IPPaaS enrollment failed","path":"/verify/review","session_duration":209.360014,"user_id":"01d764fa-5145-48dd-8113-9e7f326dcf7a","locale":"en","user_ip":"::1","hostname":"localhost","pid":3265,"service_provider":null,"trace_id":null,"git_sha":"244c456e","git_branch":"sbachstein/lg-6872-add-error-handling","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36","browser_name":"Chrome","browser_version":"104.0.0.0","browser_platform_name":"macOS","browser_platform_version":"10.15.7","browser_device_name":"Unknown","browser_mobile":false,"browser_bot":false},"time":"2022-08-11T15:54:55.360Z","id":"c3de9f97-71aa-4341-9b29-79368d6f554a","visitor_id":"90e85b4f-4a40-4429-9bbd-d4a398c9fc58","visit_id":"e8a03ee5-5fc9-4ef2-b16b-a300d3c19004"}

🔍 Testing instructions

You can try this out locally by setting usps_mock_fallback to true in your application.yml.default file and using one of the special first names to trigger a particular error:

  • usps waiting - timeout error
  • usps client error - 400 error response
  • usps server error - 500 error response
  • usps invalid response - missing enrollment code from USPS

You can switch between fsm v1 and fsm v2 by changing the value of idv_api_enabled_steps in your application.yml.default file:

  • FSM v1: '[]'
  • FSM v2: '["password_confirm", "personal_key","personal_key_confirm"]'

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

Reviewing before WIP removed to help speed things along.

Seems like the following AC is already handled by #6624, but maybe @sheldon-b or @tomas-nava should confirm.

Coordinate with the engineer working on LG-6089 if necessary to establish a consistent format for saving the Post Office address to the session and database; then make sure that the work for LG-6348 (PR #6580) is modified to display the address format correctly.

@tomas-nava
Copy link
Contributor

regarding...

Seems like the following AC is already handled by #6624

Yes, that's handled in #6624; the work in this PR isn't addressing all the AC in LG-6872, the primary PRs that did that were #6615 and #6619. This is follow-on work to beef up the error handling.

@sheldon-b sheldon-b changed the title (WIP) LG-6872: Handle errors when creating USPS enrollment LG-7241: Handle errors when creating USPS enrollment Aug 11, 2022
@sheldon-b sheldon-b marked this pull request as ready for review August 11, 2022 20:04
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks like there's a couple failures in the build (missing fixture file?), but otherwise LGTM 👍

Comment on lines +35 to +41
address = [pii['address1'], pii['address2']].select(&:present?).join(' ')
applicant = UspsInPersonProofing::Applicant.new(
{
unique_id: enrollment.usps_unique_id,
first_name: pii['first_name'],
last_name: pii['last_name'],
address: pii['address1'],
# do we need address2?
address: address,
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on some of the testing feedback we've received, I'm hopeful this change may help fix some issues we've seen with apartment / unit numbers!

@@ -1,26 +1,36 @@
require './spec/support/usps_ipp_fixtures'
Copy link
Contributor

Choose a reason for hiding this comment

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

It catches my attention that we're loading spec code from the app code, vs. the other way around. I suppose it's probably not an issue? The alternative could be to move the mock data somewhere in this folder (e.g. app/services/usps_in_person_proofing/mock/responses/request_facilities.json), but I also don't see much prior art for that, so could leave it as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Only after I wrote this did I notice you already self-reported at #6629 (comment) 😄 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of having a file in mock/ for this, it does feel weird to be pulling in a spec fixture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I moved things around in baff25e

  1. Move all of the response json files to app/services/usps_in_person_proofing/mock/responses/
  2. Move the UspsIppFixtures class to UspsInPersonProofing::Mock::Fixtures
  3. Update all of the references to the fixtures to the new class

Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@sheldon-b sheldon-b merged commit 22cd26d into main Aug 15, 2022
@sheldon-b sheldon-b deleted the sbachstein/lg-6872-add-error-handling branch August 15, 2022 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants