#Appwrite error handling
1 messages · Page 1 of 1 (latest)
Instead of checking for status codes, I would utilize Appwrites error types to create better messages that are tailored to Appwrites exceptions.
https://appwrite.io/docs/advanced/platform/error-handling#common-error-types-and-suggested-messages
https://appwrite.io/docs/advanced/platform/response-codes#platform-errors
So for sign-up, sign-in i have to impliment all error types in a switch case??
also how do i know that which type of error can be throwned for sign-up, signin and other stuffs?
No you would only handle the errors that pertain to the action you're performing.
But I believe the exception appwrite throws has a user friendly message associated with it. You can just return that instead. It's what the appwrite website does.
If you want to create your own error messages here are the types that are thrown during auth processes.
https://appwrite.io/docs/advanced/platform/response-codes#authentication-errors
Here just read the description to see what is important to you. For example you probably want to handle user_already_exists in your sign up form. Or user_invalid_credentials in your login form.
I got it, so as you said appwrite returns clear error messages so i can just do this?
catch (error: unknown) {
let errorMessage = "Authentication failed. Please try again later.";
if (error instanceof AppwriteException) {
errorMessage = error.message;
}
console.error("Authentication error:", error);
return {
success: false,
error: errorMessage,
};
}
imo that's fine.