Repository navigation
fix(data-engine): reject aborted requests with an aborted FetchError - #1446
Merged
Merged
Conversation
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>
|
edoardo
approved these changes
Nov 9, 2026
KaiVandivier
approved these changes
Nov 9, 2026
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))
Contributor
|
🎉 This PR is included in version 3.17.5 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.



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
useDataQueryanduseDataMutationdo already.Description
When a request made through the data engine is aborted with an
AbortSignal, it rejects with aFetchErrorof typenetwork("An unknown network error occurred"). TheAbortErroris only visible inerror.details.abortedis already a declaredFetchErrorTypeName, but until now only the manualabort()inuseDataQueryproduced it.This causes two problems:
typeto 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/analyticsnow passes asignalthrough toengine.query.DataEngine.queryandmutatecallonErrorbeforeuseDataQuerychecks whether its own signal was aborted. So when the hook aborts a previous request, on a refetch or when the component unmounts, the app'sonErrorreceives a "network error".In
fetchData, afetchrejection now becomes aFetchErrorof typeabortedwith the message'Aborted'if the error's name isAbortErroror the request's signal has already aborted.'Aborted'is the message the manualabort()inuseDataQueryalready uses. The original error stays indetails. Every other rejection is still anetworkerror.Compatibility
'aborted'is already part ofFetchErrorTypeName.errorstate returned byuseDataQueryanduseDataMutationdoesn't change, because the hooks ignore errors that arrive after their signal has aborted.onErrorcallbacks and code that callsengine.query/engine.mutatedirectly now getabortedinstead ofnetworkfor aborted requests. Only code that recognised aborts by checkingtype === 'network'needs to change, and the original error is still indetails.Checklist
Have written DocumentationNot needed: the docs don't listFetchErrortypes, andabortedis already part of the public type.fetchData.test.tscover three cases: a plain fetch failure staysnetwork, a rejection with anAbortErrorbecomesaborted, and a rejection with any other error after the signal has aborted also becomesaborted.event-visualizer-appI 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.