Skip to content

Commit

Permalink
chore(bots): return error in case announce failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Aug 17, 2023
1 parent 6801acd commit 68e06b7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/bots/internal/grpc_impl/grpc_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpc_impl
import (
"context"
"errors"
"fmt"
"strings"

"github.com/samber/do"
Expand Down Expand Up @@ -83,6 +84,12 @@ func (c *botsGrpcServer) DeleteMessage(ctx context.Context, data *bots.DeleteMes

func (c *botsGrpcServer) SendMessage(ctx context.Context, data *bots.SendMessageRequest) (*emptypb.Empty, error) {
if data.Message == "" {
c.logger.Sugar().Error(
"empty message",
zap.String("channelId", data.ChannelId),
zap.String("channelName", data.ChannelId),
zap.String("text", data.Message),
)
return &emptypb.Empty{}, errors.New("empty message")
}

Expand Down Expand Up @@ -138,6 +145,7 @@ func (c *botsGrpcServer) SendMessage(ctx context.Context, data *bots.SendMessage
)
if err != nil {
c.logger.Sugar().Error(err, zap.String("channelId", channel.ID))
return nil, err
} else if announceReq.ErrorMessage != "" {
slog.Error(
"cannot do announce "+announceReq.ErrorMessage,
Expand All @@ -147,6 +155,10 @@ func (c *botsGrpcServer) SendMessage(ctx context.Context, data *bots.SendMessage
slog.String("message", data.Message),
slog.Int("code", announceReq.StatusCode),
)
return nil, fmt.Errorf(
"cannot do announce, channelId: %s, message: %s, err: %s", channel.ID, data.Message,
announceReq.ErrorMessage,
)
}
} else {
bot.SayWithRateLimiting(*channelName, data.Message, nil)
Expand Down

0 comments on commit 68e06b7

Please sign in to comment.