On page load I check if the user is logged in and then store that account information to a global state. The documentation says the account.get() call throws an AppwriteException so I wrap it in a try catch block but it still shows on the dev tools:
try {
const userSession = await account.get();
if (userSession) {
setSession(userSession);
}
} catch (error: any) {
// AppwriteException: User (role: guests) missing scope (account)
// User is not logged in - do nothing
}
Even though I wrapped this in a try catch block, I still get GET https://appwrite.mydomain.com/v1/account 401 on the dev tools. I know it is harmless but is it possible to not have that show up on the dev tools? Would it be possible to set these async calls so that you can destructure the data returned or the error if an error does occur:
const { data: userSession, error } = await account.get();
Yep, that's expected. You're doing it right. Those show up whenever there's any http call that results in > 400 status code
Oh I see.. hmmm.. I guess I can just leave it then. I just hate how it feels like I coded things wrong whenever I see errors like that on the console.
Isn't that what I'm already doing?
Yes, my bad
I feel that this is the right way of doing things... my only complain is with the "any" for the error type.... i just feel that it should be strongly typed... something like
catch (error: AppwriteException) because the sdk always throws this...
@Olivier Pavie no I think that's fine, in Javascript you can throw any errors as mentioned here https://fettblog.eu/typescript-typing-catch-clauses/ so it needs to be any, you can then use instanceof to check its type:
try {
const userSession = await account.get();
if (userSession) {
setSession(userSession);
}
} catch (error: any) {
if (error instanceof AppwriteException) {
if (error.message.toLowerCase() === 'user (role: guests) missing scope (account)') {
// AppwriteException: User (role: guests) missing scope (account)
// User is not logged in - do nothing
}
}
}
Recommended threads
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...
- GitHub Student Login Loop Issue
signed up using my GitHub Student Developer Pack. However, whenever I click "Sign in with GitHub", I get stuck on the login page. No matter how many times I try...
- Google OAuth Not Working on Brave/Firefo...
I'm having an issue with Google OAuth in my React + Appwrite app. After login, the dashboard is accessible only in Microsoft Edge, but fails in Brave and Firefo...