Skip to content

Commit 67a7a67

Browse files
AchoArnoldCopilot
andcommitted
fix(api): correct diagnostic messages
Keep logged IDs, limits, and regex details aligned with the operations that failed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5e77d279-9f4a-46bc-97b1-db6975c76faf
1 parent dd29824 commit 67a7a67

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

api/pkg/handlers/integration_3cx_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (h *Integration3CXHandler) Messages(c fiber.Ctx) error {
7474
request.Sanitize()
7575
message, err := h.messageService.SendMessage(ctx, request.ToMessageSendParams(h.userIDFomContext(c), c.OriginalURL()))
7676
if err != nil {
77-
ctxLogger.Error(stacktrace.Propagate(err, "cannot send [3cx] message with paylod [%s]", c.Body()))
77+
ctxLogger.Error(stacktrace.Propagate(err, "cannot send [3cx] message with payload [%s]", c.Body()))
7878
return h.responseInternalServerError(c)
7979
}
8080

api/pkg/handlers/webhook_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (h *WebhookHandler) Store(c fiber.Ctx) error {
159159
}
160160

161161
if len(webhooks) == 10 {
162-
ctxLogger.Warn(stacktrace.NewError("user with ID [%s] wants to create more than 5 webhooks", h.userIDFomContext(c)))
162+
ctxLogger.Warn(stacktrace.NewError("user with ID [%s] wants to create more than 10 webhooks", h.userIDFomContext(c)))
163163
return h.responsePaymentRequired(c, "You can't create more than 10 webhooks contact us to upgrade to our enterprise plan.")
164164
}
165165

api/pkg/repositories/gorm_user_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (repository *gormUserRepository) Load(ctx context.Context, userID entities.
196196
user := new(entities.User)
197197
err := repository.db.WithContext(ctx).First(user, userID).Error
198198
if errors.Is(err, gorm.ErrRecordNotFound) {
199-
return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, "user with ID [%s] does not exist", user.ID))
199+
return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, "user with ID [%s] does not exist", userID))
200200
}
201201

202202
if err != nil {

api/pkg/services/service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func (service *service) createEvent(eventType string, source string, payload any
3030
}
3131

3232
func (service *service) getFormattedNumber(ctxLogger telemetry.Logger, phoneNumber string) string {
33-
matched, err := regexp.MatchString("^\\+?[1-9]\\d{9,14}$", phoneNumber)
33+
const phoneNumberPattern = "^\\+?[1-9]\\d{9,14}$"
34+
35+
matched, err := regexp.MatchString(phoneNumberPattern, phoneNumber)
3436
if err != nil {
35-
ctxLogger.Error(stacktrace.Propagate(err, "error while matching phoneNumber [%s] with regex [%s]", phoneNumber, "^\\+?[1-9]\\d{10,14}$"))
37+
ctxLogger.Error(stacktrace.Propagate(err, "error while matching phoneNumber [%s] with regex [%s]", phoneNumber, phoneNumberPattern))
3638
return phoneNumber
3739
}
3840
if !matched {

api/pkg/validators/discord_handler_validator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (validator *DiscordHandlerValidator) ValidateStore(ctx context.Context, req
9696
}
9797

9898
if _, _, err := validator.client.Guild.Get(ctx, request.ServerID); err != nil {
99-
ctxLogger.Error(validator.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot fetch discord channel with ID [%s]", request.IncomingChannelID)))
100-
result.Add("server_id", fmt.Sprintf("cannot fetch discord server with ID [%s] make sure the bot has access to the channel", request.ServerID))
99+
ctxLogger.Error(validator.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot fetch discord server with ID [%s]", request.ServerID)))
100+
result.Add("server_id", fmt.Sprintf("cannot fetch discord server with ID [%s] make sure the bot has access to the server", request.ServerID))
101101
}
102102

103103
return result
@@ -144,8 +144,8 @@ func (validator *DiscordHandlerValidator) ValidateUpdate(ctx context.Context, re
144144
}
145145

146146
if _, _, err := validator.client.Guild.Get(ctx, request.ServerID); err != nil {
147-
ctxLogger.Error(validator.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot fetch discord channel with ID [%s]", request.IncomingChannelID)))
148-
result.Add("server_id", fmt.Sprintf("cannot fetch discord server with ID [%s] make sure the bot has access to the channel", request.ServerID))
147+
ctxLogger.Error(validator.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, "cannot fetch discord server with ID [%s]", request.ServerID)))
148+
result.Add("server_id", fmt.Sprintf("cannot fetch discord server with ID [%s] make sure the bot has access to the server", request.ServerID))
149149
}
150150

151151
return result

0 commit comments

Comments
 (0)