
Is it possible to make the SDK functions fail without logging about it in the JS console?
I'm wrapping the call in question in a try { ... } catch (e) { ... }
statement, however a 404 is still being reported.
My use case is I'm using a team to signify admin users, and checking each user to see if they belong to the admin team to determine whether or not to show the admin UI.
I'm currently teams.listMemberships
to query if the current user is a member of the 'admin' team. If there is a better way of doing this let me know! π

What you mean by 404
from who? on the REST request?
Also, is this is the cloud or a self-hosted?

This will be a cloud project, and the 404 in question is coming from the following code (on a non-admin user):
let isAdmin = false;
try {
const adminResults = await teams.listMemberships('admin', undefined, auth_id!);
if (adminResults.memberships.length === 1) {
const {userId: adminUserId} = adminResults.memberships[0];
isAdmin = (auth_id === adminUserId);
}
}
catch (e) {}

Perhaps this is just Chrome's default behaviour?

It's not the end of the world, it's just I'm expecting it to 404 in a lot (the majority) of cases, so if I can suppress this somehow it'd make for a much cleaner console

Ohh got you. I thought you meant Appwrite functions

So, In this case

Oh no, client SDKs, my apologies

No no, my bad

Appwrite uses throw logic to handle this things. So to make cleaner or silently failed it will probably be best to wrap it within a function, like so:
function isAdmin() {
try {
const adminResults = await teams.listMemberships('admin', undefined, auth_id!);
if (adminResults.memberships.length === 1) {
const {userId: adminUserId} = adminResults.memberships[0];
return (auth_id === adminUserId);
}
}
catch (e) {}
return false;
}

What makes this try
/ catch
different from what I have?
I'm still awaiting the results of the listMemberships()
promise inside a try statement, so I'm a little confused here.
It might also be worth noting that my original code is already nested inside another try/catch (which includes reaching out for prior user data), and is already inside a reusable function getUserData(auth_id)
, the goal of which is to retrieve user data about a given user (including if they have admin privileges or not).

I do get the feeling this may just be Chrome reporting a network request has failed tho

In which case there's likely not much I can do

I doesn't make different logically, just programmatic flow.

When team not found, you'll always going to get 404.

But when the error is enclosed within you try/catch
block, then, it doesn't affect your app and the end user

Is that make sense?

Yeah that makes sense and is how I was using it, but what I'm looking for is a way to silence the 404 being reported in the console, so that if a dev-user pops it open they don't see 10000 404 errors

Mmm, I don't think you can do that. Is like you can't hide any other XHR requests to your Appwrite.

Yeahh, I kinda figured, oh well thought I'd ask

Thank you π

Please mark this post as SOLVED or CLOSED if no further help is needed.

[Solved] Make SDK functions fail silently?

i wouldn't call teams.listMemberships()
. I would use teams.list()
and check if the admin team is returned

Okay thanks Steven, I'll revisit this in a bit π
Recommended threads
- Sharing cookies
Hi, Iβm using Appwrite Cloud, and I have a setup where my Appwrite backend is hosted on a subdomain (e.g., api.example.com), while my frontend (Next.js app) and...
- Organization not exists anymore
Hello! We have a problem with a cloud database. We are on the Free plan, but after a refresh the site wants me to create a new organisation, and I not see the c...
- JSON and Object Support in Collection do...
I am working with Next.Js and Appwrite Cloud, I am relatively New to Appwrite but i have noticed there is no direct support of JSON and Object support in attrib...
