Fix compile errors, test errors

This commit is contained in:
lash 2024-12-14 11:56:31 +00:00
parent c820e89cb7
commit 8d4d8a48e0
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 7 additions and 8 deletions

View File

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
@ -45,14 +44,14 @@ type atRequestParser struct{}
func (arp *atRequestParser) GetSessionId(rq any) (string, error) { func (arp *atRequestParser) GetSessionId(rq any) (string, error) {
rqv, ok := rq.(*http.Request) rqv, ok := rq.(*http.Request)
if !ok { if !ok {
log.Printf("got an invalid request:", rq) logg.Warnf("got an invalid request", "req", rq)
return "", handlers.ErrInvalidRequest return "", handlers.ErrInvalidRequest
} }
// Capture body (if any) for logging // Capture body (if any) for logging
body, err := io.ReadAll(rqv.Body) body, err := io.ReadAll(rqv.Body)
if err != nil { 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) return "", fmt.Errorf("failed to read request body: %v", err)
} }
// Reset the body for further reading // 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)} bodyLog := map[string]string{"body": string(body)}
logBytes, err := json.Marshal(bodyLog) logBytes, err := json.Marshal(bodyLog)
if err != nil { if err != nil {
log.Printf("failed to marshal request body:", err) logg.Warnf("failed to marshal request body", "err", err)
} else { } else {
log.Printf("Received request:", string(logBytes)) logg.Debugf("received request", "bytes", logBytes)
} }
if err := rqv.ParseForm(); err != nil { 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) 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) formattedNumber, err := common.FormatPhoneNumber(phoneNumber)
if err != nil { 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") return "", fmt.Errorf("failed to format number")
} }

View File

@ -213,7 +213,7 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
store := h.userdataStore 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 err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
logg.InfoCtxf(ctx, "Creating an account because it doesn't exist") logg.InfoCtxf(ctx, "Creating an account because it doesn't exist")