How are you supposed to handle errors on the client? API is very inconsistent
- I appreciate all the efforts the authors have put into making this library but I'll be brutally honest
- Something as basic as error handling has absolutely horrible documentation
- I am talking specifcally about handling errors in my sveltekit client that uses a separate express backend
- Now before you point it, yes I have read the docs
- This is my current catch block for all the forms like login, signup, forgot and reset
- Nothing fancy, just email and password with a cloudflare turnstile setup on the server
- Let me tell you the issues in this
- Sometimes the BetterAuthError object will have the following structure
Client | Better Auth
Better Auth client library for authentication.
1 Reply
- Notice how there is no code here. I triggered this by simply not giving the backend a CAPTCHA token
- Shut the backend down comnpletely and it triggers the else block where the network error gets handled
- Now lets give it an invalid email and see what happens after disabling all the HTML validation measures
- Funnily it says nothing that the email is the field that is invalid
- So when is BetterAuthError thrown on the frontend? Do I need to catch this?
- How do I differentiate between the conditions where error object only contains a message vs error containing both a code and a message? How do I know which field failed the validation error? What about CORS errors?
- Guys, this really needs better documentation and work