diff --git a/internal/service/chat/chat_errors.go b/internal/service/chat/chat_errors.go index 27d46a1..6ebbed3 100644 --- a/internal/service/chat/chat_errors.go +++ b/internal/service/chat/chat_errors.go @@ -14,4 +14,5 @@ var ( ErrJoinDirectChat = errors.New("joining direct chat is not possible") ErrRecipientNotFound = errors.New("recipient not found") ErrMessageStoreCreation = errors.New("failed to create message store for chat") + ErrPublishEvent = errors.New("failed to publish event to streamer") ) diff --git a/internal/service/chat/chat_service.go b/internal/service/chat/chat_service.go index 2e1ba1d..177d208 100644 --- a/internal/service/chat/chat_service.go +++ b/internal/service/chat/chat_service.go @@ -185,13 +185,16 @@ func (s *ChatService) CreateDirect(ctx context.Context, userID model.UserID, rec return nil, &vali.Varror{Error: service.ErrProtoMarshaling} } - s.eventPublisher.Publish(&eventsv1.StreamEvent{ + err = s.eventPublisher.Publish(&eventsv1.StreamEvent{ SenderUserId: userID, ReceiversUserId: []model.UserID{ finalRecipientUserID, }, Payload: payloadProtoBuf, }) + if err != nil { + return nil, &vali.Varror{Error: ErrPublishEvent} + } return chatDTO, nil } diff --git a/internal/service/common_errors.go b/internal/service/common_errors.go index 95bcd05..d00e52a 100644 --- a/internal/service/common_errors.go +++ b/internal/service/common_errors.go @@ -2,6 +2,4 @@ package service import "errors" -var ( - ErrProtoMarshaling = errors.New("proto marshaling failed") -) +var ErrProtoMarshaling = errors.New("proto marshaling failed") diff --git a/utils/random/random.go b/utils/random/random.go index dcc37bc..21019d5 100644 --- a/utils/random/random.go +++ b/utils/random/random.go @@ -9,8 +9,8 @@ import ( const UserIDLength = 8 var ( - min = int64(math.Pow(10, float64(UserIDLength)-1)) - max = int64(math.Pow(10, float64(UserIDLength))) - 1 + minInt = int64(math.Pow(10, float64(UserIDLength)-1)) + maxInt = int64(math.Pow(10, float64(UserIDLength))) - 1 ) func GenerateUserID() int { @@ -22,7 +22,7 @@ func GenerateUserID() int { panic(err) } - randomNumber = int64(binary.BigEndian.Uint64(buf))%(max-min+1) + min + randomNumber = int64(binary.BigEndian.Uint64(buf))%(maxInt-minInt+1) + minInt return int(randomNumber) }