Skip to content

Conversation

@leo91000
Copy link

@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.

- 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.)

1 participant