From 8d4d8a48e02367842b43fd5940bfbaf13a56a2ba Mon Sep 17 00:00:00 2001 From: lash Date: Sat, 14 Dec 2024 11:56:31 +0000 Subject: [PATCH] Fix compile errors, test errors --- cmd/africastalking/main.go | 13 ++++++------- internal/handlers/ussd/menuhandler.go | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 7d1caa8..98864db 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -7,7 +7,6 @@ import ( "flag" "fmt" "io" - "log" "net/http" "os" "os/signal" @@ -45,14 +44,14 @@ type atRequestParser struct{} func (arp *atRequestParser) GetSessionId(rq any) (string, error) { rqv, ok := rq.(*http.Request) if !ok { - log.Printf("got an invalid request:", rq) + logg.Warnf("got an invalid request", "req", rq) return "", handlers.ErrInvalidRequest } // Capture body (if any) for logging body, err := io.ReadAll(rqv.Body) if err != nil { - log.Printf("failed to read request body:", err) + logg.Warnf("failed to read request body", "err", err) return "", fmt.Errorf("failed to read request body: %v", err) } // Reset the body for further reading @@ -62,13 +61,13 @@ func (arp *atRequestParser) GetSessionId(rq any) (string, error) { bodyLog := map[string]string{"body": string(body)} logBytes, err := json.Marshal(bodyLog) if err != nil { - log.Printf("failed to marshal request body:", err) + logg.Warnf("failed to marshal request body", "err", err) } else { - log.Printf("Received request:", string(logBytes)) + logg.Debugf("received request", "bytes", logBytes) } if err := rqv.ParseForm(); err != nil { - log.Printf("failed to parse form data: %v", err) + logg.Warnf("failed to parse form data", "err", err) return "", fmt.Errorf("failed to parse form data: %v", err) } @@ -79,7 +78,7 @@ func (arp *atRequestParser) GetSessionId(rq any) (string, error) { formattedNumber, err := common.FormatPhoneNumber(phoneNumber) if err != nil { - fmt.Printf("Error: %v\n", err) + logg.Warnf("failed to format phone number", "err", err) return "", fmt.Errorf("failed to format number") } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index b47e31f..dff01d1 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -213,7 +213,7 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte) return res, fmt.Errorf("missing session") } store := h.userdataStore - _, err = store.ReadEntry(ctx, sessionId, common.DATA_ACCOUNT_CREATED) + _, err = store.ReadEntry(ctx, sessionId, common.DATA_PUBLIC_KEY) if err != nil { if db.IsNotFound(err) { logg.InfoCtxf(ctx, "Creating an account because it doesn't exist")