Skip to content

fix(data-engine): reject aborted requests with an aborted FetchError - #1446

Merged
KaiVandivier merged 1 commit into
masterfrom
fix/aborted-fetch-error-type
Nov 9, 2026
Merged

KaiVandivier merged 1 commit into
masterfrom
fix/aborted-fetch-error-type

Conversation

@HendrikThePendric

@HendrikThePendric HendrikThePendric commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Related to DHIS2-22407: in our new line-list pager we want to keep buttons enabled while requests are pending, so cancellation becomes important. We use the data-engine directly so need it to return the correct error, as useDataQuery and useDataMutation do already.


Description

When a request made through the data engine is aborted with an AbortSignal, it rejects with a FetchError of type network ("An unknown network error occurred"). The AbortError is only visible in error.details. aborted is already a declared FetchErrorTypeName, but until now only the manual abort() in useDataQuery produced it.

This causes two problems:

  • Callers can't use type to tell an abort from a real network failure, so they show a network error for a request they cancelled on purpose. For example, the line list in the event-visualizer-app aborts the analytics request for each page the user clicks past, and @dhis2/analytics now passes a signal through to engine.query.
  • DataEngine.query and mutate call onError before useDataQuery checks whether its own signal was aborted. So when the hook aborts a previous request, on a refetch or when the component unmounts, the app's onError receives a "network error".

In fetchData, a fetch rejection now becomes a FetchError of type aborted with the message 'Aborted' if the error's name is AbortError or the request's signal has already aborted. 'Aborted' is the message the manual abort() in useDataQuery already uses. The original error stays in details. Every other rejection is still a network error.

Compatibility

  • No type change: 'aborted' is already part of FetchErrorTypeName.
  • The error state returned by useDataQuery and useDataMutation doesn't change, because the hooks ignore errors that arrive after their signal has aborted.
  • onError callbacks and code that calls engine.query / engine.mutate directly now get aborted instead of network for aborted requests. Only code that recognised aborts by checking type === 'network' needs to change, and the original error is still in details.

Checklist

  • Have written Documentation Not needed: the docs don't list FetchError types, and aborted is already part of the public type.
  • Has tests coverage: new tests in fetchData.test.ts cover three cases: a plain fetch failure stays network, a rejection with an AbortError becomes aborted, and a rejection with any other error after the signal has aborted also becomes aborted.
  • Has been tested manually: In event-visualizer-app I worked on a new feature that relies on cancellation and with this PR plus feat(analytics-api): allow aborting analytics requests with an AbortSignal analytics#1879 it all worked properly.

When fetch rejects because its AbortSignal fired, fetchData wrapped the
AbortError in a FetchError of type 'network'. Callers could not tell a
deliberate cancellation from a real network failure, and onError
callbacks received a "network error" whenever useDataQuery aborted a
previous request on refetch or unmount.

Map rejections whose name is AbortError, or whose request signal has
aborted, to the existing 'aborted' type with the same 'Aborted' message
useDataQuery's manual abort() uses. The original error stays in details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@KaiVandivier
KaiVandivier merged commit 165f105 into master Nov 9, 2026
37 checks passed
@KaiVandivier
KaiVandivier deleted the fix/aborted-fetch-error-type branch November 9, 2026 21:22
dhis2-bot added a commit that referenced this pull request Nov 9, 2026
## [3.17.5](v3.17.4...v3.17.5) (2026-11-09)

### Bug Fixes

* **data-engine:** reject aborted requests with an aborted FetchError ([#1446](#1446)) ([165f105](165f105))
@dhis2-bot

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants