Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Gracefully handle non-English postcodes #244

Merged

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Jan 8, 2025

What does this PR do?

  • Adds a custom APIError class
  • Implements this where we have specific errors which require feedback for the user
  • Handles these errors on the frontend and updates the form errors accordingly
  • Closes Handle non-English postcodes #232
Screen.Recording.2025-01-08.at.16.17.44.mov

Copy link

vercel bot commented Jan 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fairhold-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 11:57am

@DafyddLlyr DafyddLlyr changed the base branch from main to dp/price-paid-summary-table January 8, 2025 16:21
@DafyddLlyr DafyddLlyr changed the base branch from dp/price-paid-summary-table to dp/query-pp-summary-table January 8, 2025 16:21
Comment on lines +76 to +88
case "ITL3_NOT_FOUND":
case "INSUFFICIENT_PRICES_PAID_DATA":
methods.setError(
"housePostcode",
{ message:
"Insufficient data for this postcode. Please try again with a different postcode"
}
);
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could handle these two cases differently, but right now this is a little white-lie about non-English postcodes.

@DafyddLlyr DafyddLlyr force-pushed the dp/gracefully-handle-missing-postcodes branch from 07b1e35 to 0b59b57 Compare January 8, 2025 16:25
@DafyddLlyr DafyddLlyr requested a review from a team January 8, 2025 16:33
@DafyddLlyr DafyddLlyr marked this pull request as ready for review January 8, 2025 16:33

throw new APIError({
status: 500,
message: `Data error: Unable get get itl3 for postcode district ${postcodeDistrict}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor typo 'get get'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch - fixed in ecd1570

Copy link
Collaborator

@gabrielegranello gabrielegranello left a comment

Choose a reason for hiding this comment

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

That's very elegant! If I get it correctly:

  1. A new object APIErrorCode is created. This extends the current Error class
  2. APIErrorCode can be of 3 types: | "ITL3_NOT_FOUND" | "INSUFFICIENT_PRICES_PAID_DATA" | "UNHANDLED_EXCEPTION";
  3. If the Error code type 1 or 2 is returned by the API, we trigger the form validation with message "Insufficient data for this postcode. Please try again with a different postcode"
    Otherwise we trigger console.log with the default error message from the general Error class. I assume errors such as : failing to connect to the database or similar will follow in this category, is that correct?

@DafyddLlyr
Copy link
Contributor Author

@gabrielegranello Perfectly correct!

In future it would be nice to handle unhandled erorrs a bit better (e.g. logging the error to an eternal monitoring service, displaying a "try again" status to the user), but for now we just return the user the specific errors we care most about and throw unhandled errors.

@DafyddLlyr DafyddLlyr force-pushed the dp/query-pp-summary-table branch from b364c36 to 2a26cf3 Compare January 9, 2025 11:54
@DafyddLlyr DafyddLlyr force-pushed the dp/gracefully-handle-missing-postcodes branch from ecd1570 to 164da34 Compare January 9, 2025 11:56
@DafyddLlyr DafyddLlyr merged commit 7769894 into dp/query-pp-summary-table Jan 9, 2025
2 checks passed
DafyddLlyr added a commit that referenced this pull request Jan 9, 2025
* feat: Query new `PricePaidSummary` model

* test: Update test cases

* feat: Gracefully handle non-English postcodes (#244)

* feat: Error handling for non-English postcodes

* fix: Typos

* test: Fix tests for new API errors
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.

2 participants