Localization handling by i18n integration or throwing custom errors with predefined endpoints?

Hello Guys, I can't figure out how to customize the error response from the predefined endpoints. It's easy to do with the api actions(e.g. auth.api) but I'm trying to follow recommendations and stick to the predefined endpoints. I'm working on a monorepo with multiple front-end apps and one rest api, And I'm trying to keep my error handling centralized in the API. So I'm aware of the available hooks like onRequest, onResponse and onError but It doesn't satisfies my needs(because they are on the client). I guess I could make a shared package with client error handler but It doesn't feel right, Because the error is a response from the server and I should be able to handle it on my errorHandling middleware right next to other error instances... Anyways I think what I'm trying to do is not unusual otherwise I wouldn't write this post. I'd love to know how I can get it done if possible. And if not, Is there another approach I should consider? Or is it a feature that is planned to be developed in the future? Thanks, Afik!
1 Reply
Ping
Ping2mo ago
You could look at a community-made plugin which handles localization https://github.com/marcellosso/better-auth-localization
GitHub
GitHub - marcellosso/better-auth-localization: A localization plugi...
A localization plugin for Better Auth that automatically translates error messages. - marcellosso/better-auth-localization

Did you find this page helpful?