more info about some errors

This commit is contained in:
Ted Unangst 2019-08-30 10:16:59 -04:00
parent f0deac732d
commit a4fe9fcf25
3 changed files with 12 additions and 11 deletions

View File

@ -1060,28 +1060,28 @@ func isactor(t string) bool {
return true
}
func investigate(name string) *Honker {
func investigate(name string) (*Honker, error) {
if name == "" {
return nil
return nil, fmt.Errorf("no name")
}
if name[0] == '@' {
name = gofish(name)
}
if name == "" {
return nil
return nil, fmt.Errorf("no name")
}
log.Printf("digging up some info on %s", name)
obj, err := GetJunkFast(name)
if err != nil {
log.Printf("error investigating honker: %s", err)
return nil
return nil, err
}
t, _ := obj.GetString("type")
if !isactor(t) {
log.Printf("it's not a person! %s", name)
return nil
return nil, err
}
xid, _ := obj.GetString("id")
handle, _ := obj.GetString("preferredUsername")
return &Honker{XID: xid, Handle: handle}
return &Honker{XID: xid, Handle: handle}, nil
}

2
fun.go
View File

@ -419,7 +419,7 @@ func findhandle(xid string) string {
var handle string
err := row.Scan(&handle)
if err != nil {
p := investigate(xid)
p, _ := investigate(xid)
if p == nil {
m := re_unurl.FindStringSubmatch(xid)
if len(m) > 2 {

View File

@ -480,7 +480,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
func ximport(w http.ResponseWriter, r *http.Request) {
xid := r.FormValue("xid")
p := investigate(xid)
p, _ := investigate(xid)
if p != nil {
xid = p.XID
}
@ -1426,8 +1426,9 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
if peep == "peep" {
flavor = "peep"
}
p := investigate(url)
if p == nil {
p, err := investigate(url)
if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
log.Printf("failed to investigate honker")
return
}
@ -1435,7 +1436,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
if name == "" {
name = p.Handle
}
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
_, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
if err != nil {
log.Print(err)
return