API Error codes

Thanks for a great library! I want to display error messages in another language than English and am therefore interested to switch based on the error.body.code. So far I have come across the USER_ALREADY_EXISTS code, but doing this manually is tedious - is there any list or reference for all possible error messages? All I can find is this, which is very sparse: https://www.better-auth.com/docs/concepts/api#error-handling.
API | Better Auth
Better Auth API.
Solution:
```ts type $ERROR_CODES = { USER_NOT_FOUND: string; FAILED_TO_CREATE_USER: string; FAILED_TO_CREATE_SESSION: string;...
Jump to solution
4 Replies
kubas
kubas2mo ago
You can use the type authClient.$ERROR_CODES
Solution
kubas
kubas2mo ago
type $ERROR_CODES = {
USER_NOT_FOUND: string;
FAILED_TO_CREATE_USER: string;
FAILED_TO_CREATE_SESSION: string;
FAILED_TO_UPDATE_USER: string;
FAILED_TO_GET_SESSION: string;
INVALID_PASSWORD: string;
INVALID_EMAIL: string;
INVALID_EMAIL_OR_PASSWORD: string;
SOCIAL_ACCOUNT_ALREADY_LINKED: string;
PROVIDER_NOT_FOUND: string;
INVALID_TOKEN: string;
ID_TOKEN_NOT_SUPPORTED: string;
FAILED_TO_GET_USER_INFO: string;
USER_EMAIL_NOT_FOUND: string;
EMAIL_NOT_VERIFIED: string;
PASSWORD_TOO_SHORT: string;
PASSWORD_TOO_LONG: string;
USER_ALREADY_EXISTS: string;
EMAIL_CAN_NOT_BE_UPDATED: string;
CREDENTIAL_ACCOUNT_NOT_FOUND: string;
SESSION_EXPIRED: string;
FAILED_TO_UNLINK_LAST_ACCOUNT: string;
ACCOUNT_NOT_FOUND: string;
USER_ALREADY_HAS_PASSWORD: string;
}
type $ERROR_CODES = {
USER_NOT_FOUND: string;
FAILED_TO_CREATE_USER: string;
FAILED_TO_CREATE_SESSION: string;
FAILED_TO_UPDATE_USER: string;
FAILED_TO_GET_SESSION: string;
INVALID_PASSWORD: string;
INVALID_EMAIL: string;
INVALID_EMAIL_OR_PASSWORD: string;
SOCIAL_ACCOUNT_ALREADY_LINKED: string;
PROVIDER_NOT_FOUND: string;
INVALID_TOKEN: string;
ID_TOKEN_NOT_SUPPORTED: string;
FAILED_TO_GET_USER_INFO: string;
USER_EMAIL_NOT_FOUND: string;
EMAIL_NOT_VERIFIED: string;
PASSWORD_TOO_SHORT: string;
PASSWORD_TOO_LONG: string;
USER_ALREADY_EXISTS: string;
EMAIL_CAN_NOT_BE_UPDATED: string;
CREDENTIAL_ACCOUNT_NOT_FOUND: string;
SESSION_EXPIRED: string;
FAILED_TO_UNLINK_LAST_ACCOUNT: string;
ACCOUNT_NOT_FOUND: string;
USER_ALREADY_HAS_PASSWORD: string;
}
officialankan
officialankanOP2mo ago
Awesome! How did you find this?
kubas
kubas2mo ago
I don’t know really lmao I think I was bored and just testing authClient methods And saw that there is an type exported

Did you find this page helpful?