Skip to content

LG-14442: Add error handling and invalid character check to public usps locations controller#11470

Merged
jennyverdeyen merged 3 commits intomainfrom
jverdeyen/LG-14442-handle-usps-errors-public-po-search
Nov 13, 2024
Merged

LG-14442: Add error handling and invalid character check to public usps locations controller#11470
jennyverdeyen merged 3 commits intomainfrom
jverdeyen/LG-14442-handle-usps-errors-public-po-search

Conversation

@jennyverdeyen
Copy link
Copy Markdown
Contributor

@jennyverdeyen jennyverdeyen commented Nov 7, 2024

🎫 Ticket

Link to the relevant ticket:
LG-14442

🛠 Summary of changes

Adds error handling to the public USPS locations controller. Also adds a check for invalid characters before making the call to USPS, otherwise throwing a UspsLocationsError. Analytics added for when errors occur.

📜 Testing Plan

In the identity-site which calls this public controller, the front end checks should prevent invalid characters from being submitted before the controller should have to handle it. So instead of a manual test plan, automated tests have been added to test that this check and the error handling works.

  • Verify that the automated tests pass.

@jennyverdeyen jennyverdeyen requested review from a team and eileen-nava November 7, 2024 17:08
changelog: Internal, In-person Proofing, Adding graceful error handling and analytics in public usps locations controller
@jennyverdeyen jennyverdeyen force-pushed the jverdeyen/LG-14442-handle-usps-errors-public-po-search branch from 2ea2856 to a053ada Compare November 7, 2024 19:55
Copy link
Copy Markdown
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.

Looks good to me. I left two questions. No blocking feedback.


include IppHelper

rescue_from ActionController::InvalidAuthenticityToken,
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.

@jennyverdeyen What would cause an ActionController::InvalidAuthenticityToken error to occur?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question! My understanding is that it occurs when a there is a missing or mismatched CSRF token: https://dev.to/ben/actioncontroller-invalidauthenticitytoken-what-s-going-on-here-2828

I'm not sure more specifically how it could be triggered in this controller, but I deduced it would be worth catching since it was also being caught in the other version of this controller

Copy link
Copy Markdown
Contributor

@mitchellhenke mitchellhenke Nov 13, 2024

Choose a reason for hiding this comment

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

This controller is "public" and includes skip_forgery_protection, which means the CSRF token is not being checked. Because of that, it should be safe to remove ActionController::InvalidAuthenticityToken.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mitchellhenke Thanks for the explanation, that makes sense! I'll remove it.

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.

This was educational, thanks. 🙏🏻

)

unless candidate.has_valid_address?
raise UspsLocationsError.new
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.

What's the benefit of using raise UspsLocationsError.new instead of raise UspsLocationsError? (I'm asking because I'm curious, I'm not asking because I think it needs to be changed. I see both patterns being used in our codebase.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Sounds good. Thanks for linking the blog. 🙏🏻

Copy link
Copy Markdown
Contributor

@WilliamBirdsall WilliamBirdsall left a comment

Choose a reason for hiding this comment

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

Tests passing!

module Public
class UspsLocationsError < StandardError
def initialize
super('Unsupported characters in address field.')
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.

no biggie, but I noticed sometimes there's a pattern to add these error messages as constants. Just wanted to pop that in here as food for thought but non-blocking.

@jennyverdeyen jennyverdeyen merged commit 292840e into main Nov 13, 2024
@jennyverdeyen jennyverdeyen deleted the jverdeyen/LG-14442-handle-usps-errors-public-po-search branch November 13, 2024 18:02
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