-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: silence user presence retrieval errors #1114
Conversation
src/lib/chat/matrix-client.ts
Outdated
async getUserPresence(userId: string) { | ||
await this.waitForConnection(); | ||
|
||
if (!this.hasSharedJoinedRoom(userId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this check will silence errors where we previously attempted to fetch presence data for users without a mutual room connection 'joined / accepted'. By ensuring users share a 'joined' status in a room, we reduce unnecessary getPresence
calls.
While this mitigates the 'FORBIDDEN' error due to the absence of a shared room, the error can still be thrown for other reasons. However, this check serves as a proactive measure to prevent one of the more common causes.
We can remove this check if we don't mind console errors for unsuccessful presence data fetches due to lack of shared rooms. These are those errors:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this is a little over complicated just to remove an error from the console. Let's just check for the error code in the catch statement and not log the permission error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yeah sounds good, shall update
} catch (error) { | ||
console.error(error); | ||
} catch (error: any) { | ||
if (error && typeof error === 'object' && error.errcode !== 'M_FORBIDDEN') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an error throws I don't think it can ever be null. This would be sufficient:
if (error.errcode !== 'M_FORBIDDEN') {
What does this do?
getUserPresence
to silently handle errors without logging them to the console.Why are we making this change?
How do I test this?
Key decisions and Risk Assessment:
Things to consider:
Before: