Skip to content

LG-8788: USPS controller, refactor error handling#7812

Merged
allthesignals merged 1 commit intomainfrom
wmg/8788-usps-locations-refactor
Feb 13, 2023
Merged

LG-8788: USPS controller, refactor error handling#7812
allthesignals merged 1 commit intomainfrom
wmg/8788-usps-locations-refactor

Conversation

@allthesignals
Copy link
Contributor

@allthesignals allthesignals commented Feb 10, 2023

🎫 Ticket

Link to the relevant ticket.

🛠 Summary of changes

Attempt to refactor error handling by leveraging rescue_from Rails controller feature.

I'm not in love with the approach and open to suggestions!

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Manually simulate error
  • Check automated tests

@allthesignals allthesignals requested review from a team and JackRyan1989 February 10, 2023 19:32
@allthesignals allthesignals force-pushed the wmg/8788-usps-locations-refactor branch from e50b27c to fd45cea Compare February 10, 2023 19:37
@allthesignals
Copy link
Contributor Author

This is one situation where we are using analytics for something that isn't really typical for analytics_events. Here, we're treating error scenarios as things that belong in analytics, so the code looks awkward. In most cases, AnalyticsEvents' methods being called with a splat from a hashable value. Errors are not hashable, so we have to manually map stuff.

I wonder if there's a way to make Faraday error subclasses hashable or describable in some way? .to_analytics_event 🤷

Comment on lines +56 to +58
Faraday::TimeoutError => :unprocessable_entity,
Faraday::BadRequestError => :unprocessable_entity,
Faraday::ForbiddenError => :unprocessable_entity,
Copy link
Contributor Author

@allthesignals allthesignals Feb 10, 2023

Choose a reason for hiding this comment

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

I wish there were some dictionary of canonical HTTP errors that had things like status code and Rails' symbol. Rack::Utils has this but it's just a simple map. I was hoping Faraday error subclasses would have this info so I could just remap to the correct one!

But, I can't be sure that when Faraday::TimeoutError is instantiated, it's actually being instantiated with the correct response_body. If something times out, is it because the client gave up on waiting, or the server explicitly returned a timeout? 🤷 That's where we'd just lean on the resonse_body (and hash that!) but it seems like that's not always available...

@allthesignals allthesignals merged commit ac10bf6 into main Feb 13, 2023
@allthesignals allthesignals deleted the wmg/8788-usps-locations-refactor branch February 13, 2023 18:51
render json: {}, status: :internal_server_error
response = proofer.request_facilities(candidate)
else
response = proofer.request_pilot_facilities
Copy link
Contributor

Choose a reason for hiding this comment

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

(I know this PR was already merged - I was looking it over while reviewing the refactor of the address search controller and had a question while doing that.)

Why are we returning the pilot facilities here? What's the use case where a user would see this response? Since we've now rolled out nationwide, I'm unclear on when a user would hit this scenario.

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, that's a good question, I don't know haha. I want to remove it all but wasn't sure if product wanted it for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! We can check in with product about this. I'll ask in slack tomorrow.

@eileen-nava
Copy link
Contributor

I know this was already merged, but I wanted to chime in and say that I think it looks great! Thanks, @allthesignals ! 🙏🏻

@mitchellhenke mitchellhenke mentioned this pull request Feb 14, 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.

3 participants