Rank 1: Thread
I am calling this function to handle login, i want to handle different scenarios for password less than 8 characters, invalid credentials, etc.
const handleLogin = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
try {
setUserLoading(true);
await account.createEmailSession(email, password);
setUserLoading(false);
router.push("/app");
} catch (error) {
console.log(error);
if (error instanceof AppwriteException) {
{/* @ts-ignore */}
alert(error.response.message)
}
}
};
So I am checking if the error is an instance of AppwriteException then I just want to alert the user the message. I can see this in the browser console e.g.
AppwriteException {
name: 'AppwriteException',
code: 401,
type: 'user_invalid_credentials',
response: {
message: 'Invalid credentials. Please check the email and password.',
code: 401,
type: 'user_invalid_credentials',
version: '0.10.28'
},
stack: 'AppwriteException: Invalid credentials. Please check the email and password.\n' +
' at Client.eval (webpack-internal:///(app-client)/./node_modules/appwrite/dist/esm/sdk.js:410:27)\n' +
' at Generator.next (<anonymous>)\n' +
' at fulfilled (webpack-internal:///(app-client)/./node_modules/appwrite/dist/esm/sdk.js:41:58)',
message: 'Invalid credentials. Please check the email and password.'
}
Just accessing error.response.message but getting this error Property 'message' does not exist on type 'string'.
web sdk version: 11.0.0