[GH-ISSUE #4356] Flexible handling for Better Auth API error #27233

Closed
opened 2026-04-17 18:08:09 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @bytaesu on GitHub (Sep 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4356

Originally assigned to: @Kinfe123 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

no.

Describe the solution you'd like

It would be great if Better Auth could handle API errors more flexibly, for example:

onAPIError?: {
    throw?: boolean;
    onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>;
    errorURL?: string;
    disableErrorPage?: boolean;
};

Currently, when errorURL is set, API errors redirect to the specified path, but the default error page is still displayed.

It would be nice to have an option to disable the default HTML error page and allow to create custom error pages.

Describe alternatives you've considered

I handle multiple services with a single Auth server, so I need to pass data to the error page. A custom page is essential in this case, and it would be cleaner if the default page could be disabled.

Additional context

No response

Originally created by @bytaesu on GitHub (Sep 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4356 Originally assigned to: @Kinfe123 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. no. ### Describe the solution you'd like It would be great if Better Auth could handle API errors more flexibly, for example: ```ts onAPIError?: { throw?: boolean; onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>; errorURL?: string; disableErrorPage?: boolean; }; ``` Currently, when errorURL is set, API errors redirect to the specified path, but the default error page is still displayed. It would be nice to have an option to disable the default HTML error page and allow to create custom error pages. ### Describe alternatives you've considered I handle multiple services with a single Auth server, so I need to pass data to the error page. A custom page is essential in this case, and it would be cleaner if the default page could be disabled. ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 18:08:09 -05:00
Author
Owner

@himself65 commented on GitHub (Sep 2, 2025):

could you please provide more context? like the code to reproduce

<!-- gh-comment-id:3243691354 --> @himself65 commented on GitHub (Sep 2, 2025): could you please provide more context? like the code to reproduce
Author
Owner

@bytaesu commented on GitHub (Sep 2, 2025):

could you please provide more context? like the code to reproduce

Hi @himself65,

I’ve created a repository that fully reproduces this issue:
https://github.com/bytaesu/better-auth-temp

<!-- gh-comment-id:3243721712 --> @bytaesu commented on GitHub (Sep 2, 2025): > could you please provide more context? like the code to reproduce Hi @himself65, I’ve created a repository that fully reproduces this issue: https://github.com/bytaesu/better-auth-temp
Author
Owner

@himself65 commented on GitHub (Sep 2, 2025):

oh this is great. thank u

<!-- gh-comment-id:3243722595 --> @himself65 commented on GitHub (Sep 2, 2025): oh this is great. thank u
Author
Owner

@bytaesu commented on GitHub (Sep 2, 2025):

disabledPaths: ['/error'] helps, but it’d be cleaner to handle errors in one place in onAPIError.

<!-- gh-comment-id:3245186308 --> @bytaesu commented on GitHub (Sep 2, 2025): `disabledPaths: ['/error']` helps, but it’d be cleaner to handle errors in one place in onAPIError.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 7, 2025):

Hi, @bytaesu. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary

  • You requested enhanced error handling in Better Auth's API, specifically to disable the default error page and support custom error pages via an onAPIError configuration.
  • You provided a minimal reproducible example repository to demonstrate the issue, which I appreciated.
  • The current workaround using disabledPaths helps partially but you suggested a more centralized and cleaner approach.
  • The discussion centers on improving flexibility for managing multiple services with a single Auth server.
  • The issue remains unresolved with no recent updates.

Next Steps

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3622427487 --> @dosubot[bot] commented on GitHub (Dec 7, 2025): Hi, @bytaesu. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary** - You requested enhanced error handling in Better Auth's API, specifically to disable the default error page and support custom error pages via an `onAPIError` configuration. - You provided a minimal reproducible example repository to demonstrate the issue, which I appreciated. - The current workaround using `disabledPaths` helps partially but you suggested a more centralized and cleaner approach. - The discussion centers on improving flexibility for managing multiple services with a single Auth server. - The issue remains unresolved with no recent updates. **Next Steps** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27233