Skip to content

Commit

Permalink
Hotfix/improve error logs for debugging (#125)
Browse files Browse the repository at this point in the history
### What

Add the client_domain when logging the message where the user with the {phone_number, client_domain} pair could not be found.

Also, updated a log from error to warn.

### Why

Better debuggability.
  • Loading branch information
marcelosalloum authored Dec 13, 2023
1 parent 25b616e commit d208a08
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/data/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (wm *WalletModel) FindWallets(ctx context.Context, enabledFilter *bool) ([]
var args []interface{}

if enabledFilter != nil {
whereClause = "WHERE w.enabled = $1"
whereClause = "WHERE w.enabled = $1 "
args = append(args, *enabledFilter)
}

Expand Down
7 changes: 4 additions & 3 deletions internal/serve/httphandler/receiver_send_otp_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func (h ReceiverSendOTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
return
}

truncatedPhoneNumber := utils.TruncateString(receiverSendOTPRequest.PhoneNumber, 3)
if phoneValidateErr := utils.ValidatePhoneNumber(receiverSendOTPRequest.PhoneNumber); phoneValidateErr != nil {
extras := map[string]interface{}{"phone_number": "phone_number is required"}
if !errors.Is(phoneValidateErr, utils.ErrEmptyPhoneNumber) {
phoneValidateErr = fmt.Errorf("validating phone number %s: %w", utils.TruncateString(receiverSendOTPRequest.PhoneNumber, len(receiverSendOTPRequest.PhoneNumber)/4), phoneValidateErr)
phoneValidateErr = fmt.Errorf("validating phone number %s: %w", truncatedPhoneNumber, phoneValidateErr)
log.Ctx(ctx).Error(phoneValidateErr)
extras["phone_number"] = "invalid phone number provided"
}
Expand Down Expand Up @@ -110,7 +111,7 @@ func (h ReceiverSendOTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
}

if numberOfUpdatedRows < 1 {
log.Ctx(ctx).Warnf("updated no rows in receiver send OTP handler for phone number: %s", utils.TruncateString(receiverSendOTPRequest.PhoneNumber, len(receiverSendOTPRequest.PhoneNumber)/4))
log.Ctx(ctx).Warnf("updated no rows in ReceiverSendOTPHandler, please verify if the provided phone number (%s) and client_domain (%s) are both valid", truncatedPhoneNumber, sep24Claims.ClientDomainClaim)
} else {
sendOTPData := ReceiverSendOTPData{
OTP: newOTP,
Expand Down Expand Up @@ -140,7 +141,7 @@ func (h ReceiverSendOTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
Message: builder.String(),
}

log.Ctx(ctx).Infof("sending OTP message to phone number: %s", utils.TruncateString(receiverSendOTPRequest.PhoneNumber, 3))
log.Ctx(ctx).Infof("sending OTP message to phone number: %s", truncatedPhoneNumber)
err = h.SMSMessengerClient.SendMessage(smsMessage)
if err != nil {
httperror.InternalError(ctx, "Cannot send OTP message", err, nil).Render(w)
Expand Down
2 changes: 1 addition & 1 deletion internal/transactionsubmission/utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewHorizonErrorWrapper(err error) *HorizonErrorWrapper {

resultCodes, resCodeErr := hError.ResultCodes()
if resCodeErr != nil {
log.Errorf("parsing result_codes: %v", resCodeErr)
log.Warnf("parsing result_codes: %v", resCodeErr)
}

return &HorizonErrorWrapper{
Expand Down

0 comments on commit d208a08

Please sign in to comment.