Skip to content

fix: Add null checks for districtFetch results Refs: PALVELUKARTTA-UI-A0#1363

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/district-fetch-null-check
Draft

fix: Add null checks for districtFetch results Refs: PALVELUKARTTA-UI-A0#1363
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/district-fetch-null-check

Conversation

@sentry

@sentry sentry Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the TypeError: Cannot read properties of undefined (reading 'results') that occurred when districtFetch resolved with undefined.

The root cause was identified as the handleFetch utility (used by districtFetch) silently resolving with undefined on network errors, combined with calling components not defensively checking the resolved data before accessing properties like .results.

To fix this, null/undefined checks have been added at the call sites of districtFetch:

  • In src/views/AreaView/AreaView.js, a data?.results guard was added before dispatching setDistrictAddressData, and a .catch(() => {}) was added to the promise chain to prevent unhandled rejections.
  • In src/views/AddressView/utils/fetchAdministrativeDistricts.js, an early return if (!districtData?.results) return []; was added.
  • In src/views/DivisionView/fetchDivisionDistrict.js, a similar early return if (!districtData?.results) return []; was added.

These changes ensure that the application gracefully handles cases where districtFetch does not return valid data, preventing crashes.

Fixes PALVELUKARTTA-UI-A0

Refs: PL-280

@tjgofore tjgofore force-pushed the seer/fix/district-fetch-null-check branch from 7a2139c to 457b1b8 Compare June 1, 2026 05:35
@sonarqubecloud

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

@azure-pipelines

Copy link
Copy Markdown

PALVELUKARTTA-UI branch is deployed to platta: https://palvelukartta-ui-pr1363.dev.hel.ninja 🚀🚀🚀

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.

0 participants