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 return true
} }
func investigate(name string) *Honker { func investigate(name string) (*Honker, error) {
if name == "" { if name == "" {
return nil return nil, fmt.Errorf("no name")
} }
if name[0] == '@' { if name[0] == '@' {
name = gofish(name) name = gofish(name)
} }
if name == "" { if name == "" {
return nil return nil, fmt.Errorf("no name")
} }
log.Printf("digging up some info on %s", name) log.Printf("digging up some info on %s", name)
obj, err := GetJunkFast(name) obj, err := GetJunkFast(name)
if err != nil { if err != nil {
log.Printf("error investigating honker: %s", err) log.Printf("error investigating honker: %s", err)
return nil return nil, err
} }
t, _ := obj.GetString("type") t, _ := obj.GetString("type")
if !isactor(t) { if !isactor(t) {
log.Printf("it's not a person! %s", name) log.Printf("it's not a person! %s", name)
return nil return nil, err
} }
xid, _ := obj.GetString("id") xid, _ := obj.GetString("id")
handle, _ := obj.GetString("preferredUsername") 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 var handle string
err := row.Scan(&handle) err := row.Scan(&handle)
if err != nil { if err != nil {
p := investigate(xid) p, _ := investigate(xid)
if p == nil { if p == nil {
m := re_unurl.FindStringSubmatch(xid) m := re_unurl.FindStringSubmatch(xid)
if len(m) > 2 { 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) { func ximport(w http.ResponseWriter, r *http.Request) {
xid := r.FormValue("xid") xid := r.FormValue("xid")
p := investigate(xid) p, _ := investigate(xid)
if p != nil { if p != nil {
xid = p.XID xid = p.XID
} }
@ -1426,8 +1426,9 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
if peep == "peep" { if peep == "peep" {
flavor = "peep" flavor = "peep"
} }
p := investigate(url) p, err := investigate(url)
if p == nil { if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
log.Printf("failed to investigate honker") log.Printf("failed to investigate honker")
return return
} }
@ -1435,7 +1436,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
if name == "" { if name == "" {
name = p.Handle name = p.Handle
} }
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
return return