fix: fall back to manual address when lookup fails - #583
Draft
sam-drumm wants to merge 2 commits into
Draft
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Sentry
/apply/[resident]/address-historyTypeError: Cannot read properties of undefined (reading '0')Issue
A household member typed a non-UK address into the Postcode field and pressed Find address. The breadcrumb shows
GET /api/address/…returning 500 with{ message: 'Unable to look up address' }, and 11ms later a consoleTypeError: Cannot read properties of undefined (reading '0')in the minified chunk forpages/apply/[resident]/address-history, followed by the Sentry error event.The cause is that
lookUpAddressnever checkedres.ok, so it parsed the 500 error body as if it were anAddressLookupResult. The page then readr.address[0]?.UPRN, and optional chaining does not help whenaddressitself is undefined. The surroundingtry/catchdid send the user on to manual entry, which is why the session continued, but theconsole.error(e)in that catch still reported the TypeError to Sentry.Changes
lib/gateways/internal-api.ts—lookUpAddressnow throws when the response is not OK, and encodes the postcode into the URL, so a failed lookup can never be treated as a result.pages/apply/[resident]/address-history.tsx— a missing or emptyaddresslist now goes straight to manual entry instead of indexing[0], and the catch no longer logs an expected lookup failure as an error.Together this removes both the client-side throw and the reported Sentry event when Find address receives a 500, or a body with no
addressarray — including overseas or free-text input in the postcode field.Issues for Review
/api/address/[postcode]itself is untouched. Residents still fall through to manual entry rather than getting a useful message. Worth investigating whether that endpoint should return 400 with{ address: [] }for input that is not a UK postcode, ideally validating the postcode shape before calling the lookup API.addressarray now goes to manual entry rather than rendering an empty select. That looks like the better behaviour, but it is a deliberate change beyond the crash.ReferenceError: onSystemThemeChanged is not definedappears in the same session but comes from the browser or an extension, not this app. Out of scope.Steps to Reproduce
/api/address/*answering 500.TypeError: Cannot read properties of undefined (reading '0')is logged and reported to Sentry.Tests
npm test(Jest +tsc --noEmit): 280 passing, including two newlookUpAddresscases inlib/gateways/internal-api.spec.ts.node scripts/agent/new-code-coverage.mjs(≥80% statements and branches on added production source / added lines).npm run e2e:run -- --spec 'cypress/e2e/pages/apply/[resident]/address-history.cy.ts': 3 passing, including the failed-lookup fall back to manual entry.sentry/*(Chrome 768×1366): not available to this branch. Therun-cypress-e2e-sentry-prjob is added in Build/agent scripts #584 and is not onmainyet.npm run devwithHOUSING_REGISTER_APIpointing at the local API, then the reproduce steps (ornpm run e2e:run:local/npm run cypress:open:localwhen a local spec exists). The implementing agent must not run this.Agent run
f05c18ec-4631-4c95-9ba0-ef93d7b5af49d03d5594(fix: fall back to manual address when lookup fails)