Skip to content

fix: wrap plain Error from fetch as NetworkError in React Native#14850

Open
PHILLIPS71 wants to merge 2 commits into
aws-amplify:mainfrom
PHILLIPS71:fix/fetch-handler-network-error-rn
Open

fix: wrap plain Error from fetch as NetworkError in React Native#14850
PHILLIPS71 wants to merge 2 commits into
aws-amplify:mainfrom
PHILLIPS71:fix/fetch-handler-network-error-rn

Conversation

@PHILLIPS71

Copy link
Copy Markdown

Description of changes

fetchTransferHandler only caught TypeError when fetch() rejected, converting it to a named NetworkError. This is correct for browsers, where the Fetch spec mandates TypeError for network failures.

React Native's native network layer throws plain Error objects instead of TypeError. These slipped through the instanceof TypeError check, were rethrown as-is, and eventually reached assertServiceError in the auth package. Because assertServiceError treats any error with name === 'Error' as an unknown failure, it wrapped them in AuthError({ name: 'Unknown' }), discarding all network error context. Callers had no way to distinguish a network failure from a genuine unexpected error.

The fix catches all non-abort errors from fetch() and wraps them as NetworkError. Aborts are explicitly re-thrown unchanged. This is safe because fetch() only rejects for two reasons: abort signals and network failures. HTTP error responses (4xx, 5xx) resolve normally and never reach the catch block.

Checklist

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@PHILLIPS71 PHILLIPS71 requested a review from a team as a code owner June 25, 2026 03:08
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c35057a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@aws-amplify/core Patch
@aws-amplify/api-graphql Patch
@aws-amplify/api Patch
@aws-amplify/datastore Patch
aws-amplify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant