-
-
Notifications
You must be signed in to change notification settings - Fork 36
Implement mapError #556
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
base: master
Are you sure you want to change the base?
Implement mapError #556
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a new mapFailure configuration option for Queries, enabling transformation of error data before it reaches the public API (.$error store and .finished.failure event). The implementation modifies the error flow to include response headers in a responseMeta structure, which is propagated through all error paths and made available to the mapFailure mapper alongside the error object and query parameters.
Key Changes:
- Added
mapFailuremapper support tocreateQueryandcreateJsonQuerywith optional source store capability - Modified error structure throughout the fetch layer to include
responseMetacontaining response headers - Introduced
failedBeforeMapintermediate event to apply error transformation before errors reach public API
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/core/src/fetch/request.ts |
Modified requestFx to throw structured errors containing both error and optional responseMeta with headers |
packages/core/src/fetch/api.ts |
Updated apiRequestFx to preserve responseMeta through error transformation and propagate headers for preparation and validation errors |
packages/core/src/remote_operation/create_remote_operation.ts |
Implemented core mapFailure logic with new failedBeforeMap event, default identity mapper, and responseMeta propagation through all failure paths |
packages/core/src/query/create_query.ts |
Integrated mapFailure parameter into createQuery's remote operation initialization |
packages/core/src/query/create_json_query.ts |
Added mapFailure type signatures across all createJsonQuery overloads and passed it to remote operation |
packages/core/src/query/create_headless_query.ts |
Added MappedError and MapFailureSource type parameters with mapFailure configuration support |
packages/core/src/mutation/create_headless_mutation.ts |
Updated type parameters to include placeholders for MappedError and MapFailureSource (mutations don't support mapFailure yet) |
packages/core/src/query/__tests__/create_json_query.response.map_failure.test.ts |
Comprehensive test coverage for mapFailure with simple/sourced callbacks, params access, and headers availability for different error types |
packages/core/src/fetch/__tests__/request.test.ts |
Updated expectations to reflect new error structure with responseMeta |
packages/core/src/fetch/__tests__/json.response.data.test.ts |
Updated test assertions for preparation errors to include responseMeta |
packages/core/src/fetch/__tests__/json.failed.data.test.ts |
Updated test expectations for HTTP errors to include responseMeta |
packages/core/src/fetch/__tests__/api.response.extract.test.ts |
Updated preparation error test assertions |
packages/core/src/fetch/__tests__/api.response.all_in_one.test.ts |
Updated test expectations for error structure |
packages/core/src/retry/__tests__/retry.query.test.ts |
Added responseMeta: undefined to test snapshot |
packages/core/src/remote_operation/__test__/create_remote_operation.test.ts |
Added responseMeta: undefined to test snapshots |
packages/core/src/concurrency/__tests__/concurrency.test.ts |
Added responseMeta: undefined to test snapshot |
apps/website/docs/recipes/data_flow.md |
Added comprehensive documentation for error mapping stage with sourced example and headers explanation |
apps/website/docs/api/factories/create_query.md |
Documented mapFailure API for both simple function and sourced variants |
apps/website/docs/api/factories/create_json_query.md |
Added mapFailure documentation with error types and headers availability details |
packages/core/package.json |
Updated size limit from 16 kB to 16.17 kB to accommodate new feature |
.changeset/popular-panthers-hope.md |
Added changeset entry marking this as a minor release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
igorkamyshev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, some questions were asked in committee chat.
This PR introduces a new
mapErrorconfiguration option for Queries, allowing transformation of error data before it reaches.finished.failureand.$error.Features
mapErrorforcreateQueryandcreateMutation- Transform errors from effects with optional source store supportmapErrorforcreateJsonQueryandcreateJsonMutation- Transform HTTP/network/contract errors with access to response headersAPI
Implementation Details
requestFxto throw structured errors{ error, responseMeta?: { headers } }responseMetathrough the entire error flow (requestFx→apiRequestFx→createRemoteOperation)failedBeforeMapintermediate event to applymapErrorbefore errors reach public APIHttpErrorremains safely serializable (headers are passed separately, not stored in the error object)Breaking Changes
None -
mapErroris optional and all existing behavior is preserved.