Skip to content

Commit

Permalink
more info in error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Sep 30, 2024
1 parent 1ae3df8 commit 6d746d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/models/nats_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (m *NatsModel) RenewPNMToken(roomId, userId, token string) {

err = m.natsService.BroadcastSystemEventToRoom(plugnmeet.NatsMsgServerToClientEvents_RESP_RENEW_PNM_TOKEN, roomId, token, &userId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Errorf("error renewing pnm token to %s; roomId: %s; msg: %s", userId, roomId, err.Error()))
}
}

Expand All @@ -46,6 +46,6 @@ func (m *NatsModel) HandleClientPing(roomId, userId string) {

err := m.natsService.UpdateUserKeyValue(roomId, userId, natsservice.UserLastPingAt, fmt.Sprintf("%d", time.Now().UnixMilli()))
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error updating user last ping to %s; roomId: %s; msg: %s", userId, roomId, err.Error()))
}
}
3 changes: 2 additions & 1 deletion pkg/models/nats_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func (m *NatsModel) OnAfterUserJoined(roomId, userId string) {
status, err := m.natsService.GetRoomUserStatus(roomId, userId)
if err != nil {
log.Errorln(fmt.Sprintf("error GetRoomUserStatus to %s; roomId: %s; msg: %s", roomId, userId, err))
return
}
if status == natsservice.UserStatusOnline {
Expand All @@ -20,7 +21,7 @@ func (m *NatsModel) OnAfterUserJoined(roomId, userId string) {

err = m.natsService.UpdateUserStatus(roomId, userId, natsservice.UserStatusOnline)
if err != nil {
log.Warnln(err)
log.Warnln(fmt.Sprintf("Error updating user status to %s; roomId: %s; msg: %s", userId, roomId, err.Error()))
}

if userInfo, err := m.natsService.GetUserInfo(roomId, userId); err == nil && userInfo != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/models/nats_user_event.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"fmt"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
log "github.com/sirupsen/logrus"
"strings"
Expand All @@ -10,7 +11,7 @@ func (m *NatsModel) HandleInitialData(roomId, userId string) {
// send room info
rInfo, err := m.natsService.GetRoomInfo(roomId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error getting room info userId: %s, roomId: %s, msg: %s", userId, roomId, err.Error()))
_ = m.natsService.NotifyErrorMsg(roomId, err.Error(), &userId)
return
}
Expand All @@ -21,7 +22,7 @@ func (m *NatsModel) HandleInitialData(roomId, userId string) {
// send this user's info
userInfo, err := m.natsService.GetUserInfo(roomId, userId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error getting user info userId: %s, roomId: %s, msg: %s", userId, roomId, err.Error()))
_ = m.natsService.NotifyErrorMsg(roomId, err.Error(), &userId)
return
}
Expand Down Expand Up @@ -51,15 +52,15 @@ func (m *NatsModel) HandleInitialData(roomId, userId string) {
// send important info first
err = m.natsService.BroadcastSystemEventToRoom(plugnmeet.NatsMsgServerToClientEvents_RES_INITIAL_DATA, roomId, initial, &userId)
if err != nil {
log.Warnln(err)
log.Warnln("error sending RES_INITIAL_DATA event userId: %s, roomId: %s, msg: %s", userId, roomId, err.Error())

Check failure on line 55 in pkg/models/nats_user_event.go

View workflow job for this annotation

GitHub Actions / test

github.com/sirupsen/logrus.Warnln call has possible Printf formatting directive %s
}
}

func (m *NatsModel) HandleSendUsersList(roomId, userId string) {
if users, err := m.natsService.GetOnlineUsersListAsJson(roomId); err == nil && users != nil {
err := m.natsService.BroadcastSystemEventToRoom(plugnmeet.NatsMsgServerToClientEvents_RES_JOINED_USERS_LIST, roomId, users, &userId)
if err != nil {
log.Warnln(err)
log.Warnln("error sending RES_JOINED_USERS_LIST event userId: %s, roomId: %s, msg: %s", userId, roomId, err.Error())

Check failure on line 63 in pkg/models/nats_user_event.go

View workflow job for this annotation

GitHub Actions / test

github.com/sirupsen/logrus.Warnln call has possible Printf formatting directive %s
}
}
}
8 changes: 5 additions & 3 deletions pkg/models/user_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"errors"
"fmt"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
natsservice "github.com/mynaparrot/plugnmeet-server/pkg/services/nats"
Expand All @@ -11,6 +12,7 @@ import (
func (m *UserModel) RemoveParticipant(r *plugnmeet.RemoveParticipantReq) error {
status, err := m.natsService.GetRoomUserStatus(r.RoomId, r.UserId)
if err != nil {
log.Errorln(fmt.Sprintf("error GetRoomUserStatus to %s; roomId: %s; msg: %s", r.GetRoomId(), r.GetUserId(), err))
return err
}

Expand All @@ -26,20 +28,20 @@ func (m *UserModel) RemoveParticipant(r *plugnmeet.RemoveParticipantReq) error {
// send notification to be disconnected
err = m.natsService.BroadcastSystemEventToRoom(plugnmeet.NatsMsgServerToClientEvents_SESSION_ENDED, r.GetRoomId(), "notifications.room-disconnected-participant-removed", &r.UserId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error broadcasting SESSION_ENDED event to %s; roomId: %s; msg: %s", r.GetRoomId(), r.GetUserId(), err))
}

// now remove from lk
_, err = m.lk.RemoveParticipant(r.RoomId, r.UserId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error removing user from lk to %s; roomId: %s; msg: %s", r.GetRoomId(), r.GetUserId(), err))
}

// finally, check if requested to block as well as
if r.BlockUser {
_, err = m.natsService.AddUserToBlockList(r.RoomId, r.UserId)
if err != nil {
log.Errorln(err)
log.Errorln(fmt.Sprintf("error AddUserToBlockList to %s; roomId: %s; msg: %s", r.GetRoomId(), r.GetUserId(), err))
}
}

Expand Down

0 comments on commit 6d746d0

Please sign in to comment.