Y艒ten: A social tracker for your language learning journey built on the atproto.

feat(handlers/follow): use slogger #11

merged opened by brookjeynes.dev targeting master from push-trrpxxyxxmot
Labels

None yet.

Participants 1
AT URI
at://did:plc:4mj54vc4ha3lh32ksxwunnbh/sh.tangled.repo.pull/3m3bmdlgbln22
+11 -10
Diff #0
+11 -10
internal/server/handlers/follow.go
··· 1 1 package handlers 2 2 3 3 import ( 4 - "log" 5 4 "net/http" 6 5 "time" 7 6 ··· 20 19 ) 21 20 22 21 func (h *Handler) HandleFollow(w http.ResponseWriter, r *http.Request) { 22 + l := h.Logger.With("handler", "HandleFollow") 23 + 23 24 client, err := h.Oauth.AuthorizedClient(r) 24 25 if err != nil { 25 - log.Println("failed to get authorized client:", err) 26 + l.Error("failed to get authorized client", "err", err) 26 27 htmx.HxRedirect(w, "/login") 27 28 return 28 29 } 29 30 30 31 user, err := bsky.GetUserWithBskyProfile(h.Oauth, r) 31 32 if err != nil { 32 - log.Println("failed to get logged-in user:", err) 33 + l.Error("failed to get logged-in user", "err", err) 33 34 htmx.HxRedirect(w, "/login") 34 35 return 35 36 } ··· 42 43 43 44 subjectIdent, err := h.IdResolver.ResolveIdent(r.Context(), subject) 44 45 if err != nil { 45 - log.Println("failed to follow, invalid did:", err) 46 + l.Error("failed to follow, invalid did", "err", err) 46 47 htmx.HxError(w, http.StatusBadRequest, "Failed to follow profile, try again later.") 47 48 return 48 49 } 49 50 50 51 if user.Did == subjectIdent.DID.String() { 51 - log.Println("failed to follow, cannot follow yourself") 52 + l.Error("failed to follow, cannot follow yourself") 52 53 htmx.HxError(w, http.StatusBadRequest, "You cannot follow yourself.") 53 54 return 54 55 } ··· 68 69 }}, 69 70 }) 70 71 if err != nil { 71 - log.Println("failed to create follow record:", err) 72 + l.Error("failed to create follow record", "err", err) 72 73 htmx.HxError(w, http.StatusInternalServerError, "Failed to follow profile, try again later.") 73 74 return 74 75 } ··· 84 85 Set("is_mutual_follow", followStatus == db.IsMutual), 85 86 }) 86 87 if err != nil { 87 - log.Println("failed to enqueue posthog event:", err) 88 + l.Error("failed to enqueue posthog event", "err", err) 88 89 } 89 90 } 90 91 ··· 95 96 case http.MethodDelete: 96 97 follow, err := db.GetFollow(h.Db, user.Did, subjectIdent.DID.String()) 97 98 if err != nil { 98 - log.Println("failed to get follow relationship:", err) 99 + l.Error("failed to get follow relationship", "err", err) 99 100 htmx.HxError(w, http.StatusInternalServerError, "Failed to unfollow profile, try again later.") 100 101 return 101 102 } ··· 106 107 Rkey: follow.Rkey, 107 108 }) 108 109 if err != nil { 109 - log.Println("failed to delete follow record:", err) 110 + l.Error("failed to delete follow record", "err", err) 110 111 htmx.HxError(w, http.StatusInternalServerError, "Failed to unfollow profile, try again later.") 111 112 return 112 113 } ··· 119 120 Set("subject_did", subjectIdent.DID.String()), 120 121 }) 121 122 if err != nil { 122 - log.Println("failed to enqueue posthog event:", err) 123 + l.Error("failed to enqueue posthog event", "err", err) 123 124 } 124 125 } 125 126

History

1 round 0 comments
sign up or login to add to the discussion
brookjeynes.dev submitted #0
1 commit
expand
feat(handlers/follow): use slogger
expand 0 comments
pull request successfully merged