From 39b35651278ca6fbff5dfddd1fe9c19ec5707f47 Mon Sep 17 00:00:00 2001 From: Asara Date: Sun, 11 Aug 2024 00:16:31 -0400 Subject: [PATCH] chore: better logging --- nostr/nostr.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nostr/nostr.go b/nostr/nostr.go index 4d91a2c..2ab3596 100644 --- a/nostr/nostr.go +++ b/nostr/nostr.go @@ -40,13 +40,18 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) { // get owner id for nip05 request var uid int - DB.QueryRow("SELECT owner_id FROM nip05s WHERE name=$1 AND domain=$2", name, domain).Scan(&uid) + err = DB.QueryRow("SELECT owner_id FROM nip05s WHERE name=$1 AND domain=$2", name, domain).Scan(&uid) + if err != nil { + l.Error().Msgf("user (%s@%s) doesn't exist: %s", name, domain, err.Error()) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } // get the pubkey and relays associated with the nip05 user := nostrUser{} err = DB.QueryRow("SELECT pubkey, relays FROM users WHERE id=$1", uid).Scan(&user.Pubkey, &user.Relays) if err != nil { - l.Error().Msgf("unable to get user for uid %v: %s", uid, err.Error()) + l.Error().Msgf("unable to get user info for uid %v: %s", uid, err.Error()) http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } @@ -55,7 +60,7 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) { names := []string{} err = DB.Select(&names, "SELECT nip05s.name FROM nip05s JOIN users ON nip05s.owner_id = users.id WHERE nip05s.owner_id = $1", uid) if err != nil { - l.Error().Msgf("unable to get user for uid %v: %s", uid, err.Error()) + l.Error().Msgf("unable to get nip05 names for uid %v: %s", uid, err.Error()) http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } @@ -88,6 +93,7 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) { return } + l.Debug().Msgf("returning nip05 for %s@%s", name, domain) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(j)