Skip to content

LG-8738: Handle unexpected API responses when checking enrollment status#7743

Merged
tomas-nava merged 5 commits intomainfrom
tomas/lg-8738-handle-applicant-does-not-exist-errors-from-usps
Feb 1, 2023
Merged

LG-8738: Handle unexpected API responses when checking enrollment status#7743
tomas-nava merged 5 commits intomainfrom
tomas/lg-8738-handle-applicant-does-not-exist-errors-from-usps

Conversation

@tomas-nava
Copy link
Contributor

@tomas-nava tomas-nava commented Feb 1, 2023

🎫 Ticket

closes LG-8738 and LG-8737

🛠 Summary of changes

Handles three types of unexpected error responses when checking enrollment status that we've seen in non-production environments:

  • an enrollment has expired after any number of days other than 30
  • no matching unique ID was found
  • no matching enrollment code was found

This PR catches and logs those errors.

@tomas-nava tomas-nava requested review from a team and allthesignals February 1, 2023 05:28
@tomas-nava tomas-nava changed the title LG-8738: Handle unexpected API responses LG-8738: Handle unexpected API responses when checking enrollment status Feb 1, 2023
Copy link
Contributor

@eileen-nava eileen-nava left a comment

Choose a reason for hiding this comment

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

I am approving this but want to note that I didn't test it locally.

enrollment.update(deadline_passed_sent: true)
end

# check for an unexpected number of days until expiration
Copy link
Contributor

Choose a reason for hiding this comment

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

TY for this helpful comment. 🙏🏻


expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: Enrollment status updated',
hash_including(reason: 'Enrollment has expired'),
Copy link
Contributor

Choose a reason for hiding this comment

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

hash_including, TIL!

Copy link
Contributor

@JackRyan1989 JackRyan1989 left a comment

Choose a reason for hiding this comment

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

Nice! Very clear. I don't have any suggestions or changes. Tests pass locally and no other issues noticed when running locally.

Comment on lines +273 to +274
expired_after_days = response_message&.match(IPP_EXPIRED_ERROR_MESSAGE)&.[](1)
if expired_after_days.present? &&
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a good use case for named captures?

if the regex was

  IPP_EXPIRED_ERROR_MESSAGE = /More than (?<days>\d+) days have passed since opt-in to IPP/

then this could be

Suggested change
expired_after_days = response_message&.match(IPP_EXPIRED_ERROR_MESSAGE)&.[](1)
if expired_after_days.present? &&
expired_after_days = response_message&.match(IPP_EXPIRED_ERROR_MESSAGE)&.[](:days)
if expired_after_days.present? &&

or maybe getting rid of &.[] syntax

Suggested change
expired_after_days = response_message&.match(IPP_EXPIRED_ERROR_MESSAGE)&.[](1)
if expired_after_days.present? &&
match = response_message&.match(IPP_EXPIRED_ERROR_MESSAGE)
expired_after_days = match && match[:days]
if expired_after_days.present? &&

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I like that, changed in a307a61

Do you prefer match && match[:days] to match&.[](:days) because the former is more human readable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah personally, I don't like the amount of visual noise combining nil-safe navigator (.&) with brackets [] resulting in &.[]()

Comment on lines +286 to 296
def handle_unexpected_response(enrollment, response_message, reason:, cancel: true)
enrollment.cancelled! if cancel

analytics(user: enrollment.user).
idv_in_person_usps_proofing_results_job_unexpected_response(
enrollment_code: enrollment.enrollment_code,
enrollment_id: enrollment.id,
response_message: response_message,
reason: reason,
)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a specific plan for how we can be notified of these issues and respond?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, not yet. I'm going to confirm that they work in lower environments, then I'll probably write up a ticket for alerting.

@tomas-nava tomas-nava merged commit 2c1aeb8 into main Feb 1, 2023
@tomas-nava tomas-nava deleted the tomas/lg-8738-handle-applicant-does-not-exist-errors-from-usps branch February 1, 2023 19:18
@aduth aduth mentioned this pull request Feb 6, 2023
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.

5 participants