throwOnError mode? #1118

Closed
opened 2026-03-13 08:23:30 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @mmkal on GitHub (Apr 26, 2025).

Is this suited for github?

  • Yes, this is suited for github

Minor problem - it's cumbersome constantly doing

const {error, data} = await authClient.whatever.foo()
if (error) throw error
return data

Especially so when you have linter rules insisting you always throw Error instances, and when you have multiple calls so you have to rename error and data to disambiguate.

Describe the solution you'd like

A new prop you can pass into to createAuthClient which changes the return type and behaviour of the various async methods:

export const authClient = createAuthClient({
  // other options
  throwOnErrror: true,
})

Describe alternatives you've considered

Writing a wrapper for createAuthClient myself - but the types get pretty complicated and are dependent on specifics of better-auth.

Additional context

This kind of API would also be more suited to libraries like react-query which keep track of errors out of the box.

Originally created by @mmkal on GitHub (Apr 26, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Minor problem - it's cumbersome constantly doing ```ts const {error, data} = await authClient.whatever.foo() if (error) throw error return data ``` Especially so when you have linter rules insisting you always throw `Error` instances, and when you have multiple calls so you have to rename `error` and `data` to disambiguate. ### Describe the solution you'd like A new prop you can pass into to `createAuthClient` which changes the return type and behaviour of the various async methods: ```ts export const authClient = createAuthClient({ // other options throwOnErrror: true, }) ``` ### Describe alternatives you've considered Writing a wrapper for `createAuthClient` myself - but the types get pretty complicated and are dependent on specifics of better-auth. ### Additional context This kind of API would also be more suited to libraries like react-query which keep track of errors out of the box.
Author
Owner

@Bekacru commented on GitHub (Apr 28, 2025):

this is already available

export const authClient = createAuthClient({
  fetchOptions: {
    throw: true
  }
})
@Bekacru commented on GitHub (Apr 28, 2025): this is already available ```ts export const authClient = createAuthClient({ fetchOptions: { throw: true } }) ```
Author
Owner

@mmkal commented on GitHub (May 16, 2025):

Sorry missed the reply - thank you !

@mmkal commented on GitHub (May 16, 2025): Sorry missed the reply - thank you !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1118