Dear community, as I understood the best way to check for an active session is account.get() and if it returns an 401 there is no active session. Now I would prefer to handle that error more gracefully and not show an error in the console. I figured my api call would look like this
try {
const currentUser = await account.get();
console.log("API Call Current User", currentUser);
return currentUser;
} catch (error: any) {
if (error.code === 401) {
// Handle 401 Unauthorized error specifically
console.log("Unauthorized, no User Logged In")
return undefined;
}
console.error("Error fetching current user:", error);
return undefined; // Return undefined if the API call fails
}
};
However, even before the catch I get an error thrown in the console.
GET https://domain/v1/account 401 (Unauthorized)```
Is this an error thrown from the Appwrite SDK? Anyone an idea on how to handle the 401 more gracefully and avoid this "unnecessary" 401 error in the console?
Recommended threads
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...
- Migrate from cloud to localhost
Hello everyone. I need to migrate my test project from cloud to localhost, however it seems that this is possible only if a self-hosted appwrite instance it's h...