chore: better logging

This commit is contained in:
Amarpreet Minhas 2024-08-11 00:16:31 -04:00
parent 36d59958b6
commit 39b3565127

View file

@ -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)