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
TypeScript
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.
TypeScript
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?
TL;DR
Developers are seeking help to handle 401 errors more gracefully when using account.get() to check for active sessions. The provided code snippet is causing an error to be thrown in the console before the catch block can handle it. One solution is to use a middleware to intercept and handle the 401 error before it reaches the console, allowing for more graceful handling.Recommended threads
- [Self-hosted] Realtime crashes with "Mis...
- How to use Operator.arrayAppend on a rel...
Hi, is it possible to use any operator on a relationship column? I have a One to Many relationship column on a table and I would like to add entries to the colu...
- Large File Upload Issue with S3/RustFS
Hi, we are seeing a reproducible large upload failure with Appwrite 1.8.0 using S3-compatible storage through RustFS. A file upload of about 10.7 GB consistent...