Skip to content
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

Merged
merged 3 commits into from
Oct 20, 2023

Conversation

domw30
Copy link
Collaborator

@domw30 domw30 commented Oct 18, 2023

What does this do?

  • Error handling in getUserPresence to silently handle errors without logging them to the console.

Why are we making this change?

  • To reduce console noise and ensure graceful degradation in scenarios where user presence data is unavailable or erroneous.

How do I test this?

Key decisions and Risk Assessment:

Things to consider:

  1. How will this affect security?
  2. How will this affect performance?
  3. Does this change any APIs?

Before:
Screenshot 2023-10-18 at 21 43 08

@domw30 domw30 requested a review from a team October 18, 2023 20:43
async getUserPresence(userId: string) {
await this.waitForConnection();

if (!this.hasSharedJoinedRoom(userId)) {
Copy link
Collaborator Author

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:

Screenshot 2023-10-18 at 21 36 40

Copy link
Contributor

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.

Copy link
Collaborator Author

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

@domw30 domw30 merged commit 5679f47 into main Oct 20, 2023
4 checks passed
@domw30 domw30 deleted the refactor/silence-presence-errors branch October 20, 2023 09:13
} catch (error) {
console.error(error);
} catch (error: any) {
if (error && typeof error === 'object' && error.errcode !== 'M_FORBIDDEN') {
Copy link
Contributor

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') {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants