[GH-ISSUE #2039] There's no error code for "Too many requests" error. #9019

Closed
opened 2026-04-13 04:17:20 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Maqed on GitHub (Mar 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2039

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

auth.ts (server):

export const auth = betterAuth({
rateLimit: {
    enabled: true, // Enabled for dev & prod
  },
});

login-form.tsx (client):

function onSubmit(values: z.infer<typeof loginSchema>) {
    startTransition(async () => {
      const { email, password } = values;
      await authClient.signIn.email(
        {
          email,
          password,
        },
        {
          onError: (ctx) => {
            console.log({ errorCode: ctx.error.code }); // returned undefined.
          },
        },
      );
    });
  }

After submitting the form multiple time, the rate limit will work and it will console.log and error.

Current vs. Expected behavior

Current behaviour: No code for the ratelimit error message

Expected behaviour: There should be an error code for the ratelimit error message

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS [Windows: 11]
- Browser [chrome]

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @Maqed on GitHub (Mar 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2039 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce auth.ts (server): ```ts export const auth = betterAuth({ rateLimit: { enabled: true, // Enabled for dev & prod }, }); ``` login-form.tsx (client): ```tsx function onSubmit(values: z.infer<typeof loginSchema>) { startTransition(async () => { const { email, password } = values; await authClient.signIn.email( { email, password, }, { onError: (ctx) => { console.log({ errorCode: ctx.error.code }); // returned undefined. }, }, ); }); } ``` After submitting the form multiple time, the rate limit will work and it will console.log and error. ### Current vs. Expected behavior Current behaviour: No code for the ratelimit error message Expected behaviour: There should be an error code for the ratelimit error message ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS [Windows: 11] - Browser [chrome] ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:17:20 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Mar 30, 2025):

you can use status property for getting the code which is 429 ctx.error.status

<!-- gh-comment-id:2764546913 --> @Kinfe123 commented on GitHub (Mar 30, 2025): you can use status property for getting the code which is 429 ` ctx.error.status `
Author
Owner

@Maqed commented on GitHub (Mar 30, 2025):

you can use status property for getting the code which is 429 ctx.error.status

I'd prefer using an error code instead of a status because my app is internationalized. Relying on status codes would require extra checks for messages, adding boilerplate. Error codes simplify handling. Here’s my approach:

onError: (ctx) => {
    toast({
      title: tErrors(`${ctx.error.code}.title`),
      description: tErrors(`${ctx.error.code}.description`),
      variant: "destructive",
    });
<!-- gh-comment-id:2764549727 --> @Maqed commented on GitHub (Mar 30, 2025): > you can use status property for getting the code which is 429 ` > ctx.error.status > ` I'd prefer using an error code instead of a status because my app is internationalized. Relying on status codes would require extra checks for messages, adding boilerplate. Error codes simplify handling. Here’s my approach: ```tsx onError: (ctx) => { toast({ title: tErrors(`${ctx.error.code}.title`), description: tErrors(`${ctx.error.code}.description`), variant: "destructive", }); ```
Author
Owner

@Kinfe123 commented on GitHub (Mar 30, 2025):

one thing i can say is you can prepare some code-status map for those that requires based on the status.

<!-- gh-comment-id:2764559653 --> @Kinfe123 commented on GitHub (Mar 30, 2025): one thing i can say is you can prepare some code-status map for those that requires based on the status.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9019