Skip to content

fix: unusage throwError and onError property on createRouter() function#42

Merged
himself65 merged 6 commits intobetter-auth:mainfrom
ianriizky:fix/error-handler
Sep 10, 2025
Merged

fix: unusage throwError and onError property on createRouter() function#42
himself65 merged 6 commits intobetter-auth:mainfrom
ianriizky:fix/error-handler

Conversation

@ianriizky
Copy link
Contributor

@ianriizky ianriizky commented Aug 21, 2025

What changes were made?

This PR fixes the usage of error handling when creating a router using createRouter() function:

  • Clarifying how onError behaves when throwing new errors or returning void
  • Emphasizing that throwError setting remains relevant even when onError is provided
  • Adding a new code example showing how onError and throwError can work together

Why were these changes made?

These documentation improvements address issues similar to those raised in better-auth/better-auth#2400, where users needed better ways to customize error messages. The updated documentation now clearly explains:

How onError can be used to customize error handling, including:

  • Returning custom responses
  • Throwing new errors with custom messages
  • Returning void to fall back to default error handling

How throwError continues to be relevant even when onError is provided, specifically when:

  • No onError handler is provided, or
  • The onError handler returns void

These clarifications help users better understand the flexible error handling options available to them and make more informed decisions about error management in their applications.

Testing checklist

  • Documentation changes only - no code changes
  • Verified that the documentation accurately reflects the actual behavior in the code
  • Ensured examples are clear and follow best practices

Related issues

Addresses documentation needs similar to those in better-auth/better-auth#2400 and Sentry is not capturing 500 errors inside Better Auth #3617
regarding error message customization.

@ianriizky
Copy link
Contributor Author

Can I get any update on this PR? @himself65 @Bekacru etc.

Copy link
Member

@himself65 himself65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know. I will check later

@himself65 himself65 merged commit 0049cb9 into better-auth:main Sep 10, 2025
2 checks passed
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.

3 participants