Skip to content

Fix: onError hook not triggered for network errors#78

Open
leo91000 wants to merge 2 commits intobetter-auth:mainfrom
leo91000:fix/network-error-handling
Open

Fix: onError hook not triggered for network errors#78
leo91000 wants to merge 2 commits intobetter-auth:mainfrom
leo91000:fix/network-error-handling

Conversation

@leo91000
Copy link
Copy Markdown

@leo91000 leo91000 commented Dec 20, 2025

Fixes #75

Network errors (ECONNREFUSED, DNS failures, timeouts) now behave consistently with HTTP errors:

  • onError hook is called
  • Returns { data: null, error: { status: 0, statusText: "Network Error", message, cause } }
  • Throws BetterFetchError only when throw: true
  • Supports retry

Abort errors are re-thrown to preserve existing behavior.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

leo91000 added 2 commits March 2, 2026 09:26
- Wrap fetch() call in try/catch to handle network-level errors

- Network errors (ECONNREFUSED, DNS failures, etc.) now call onError hook

- Network errors return { data: null, error } instead of throwing

- Respect throw: true option for network errors

- Support retry for network errors

- Re-throw abort errors to preserve existing behavior

- Refactor error handling into shared handleError function

- Add comprehensive tests for network error scenarios

Fixes better-auth#75
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.

onError hook not triggered for network errors (ECONNREFUSED, DNS failures, etc.)

2 participants