Use log.Error instead of log.Info where necessary

Closes #5
master
Matt Baer 2024-08-30 17:38:06 -04:00
parent a25d81ce6d
commit e7781b8f65
2 changed files with 10 additions and 12 deletions

12
http.go
View File

@ -104,7 +104,7 @@ func Serve(actors map[string]Actor) {
totalLines, err := lineCounter(filename) totalLines, err := lineCounter(filename)
if err != nil { if err != nil {
log.Info("Can't read outbox.txt") log.Info("Can't read outbox.txt")
log.Info(err) log.Error(err)
return return
} }
if pageStr == "" { if pageStr == "" {
@ -126,7 +126,7 @@ func Serve(actors map[string]Actor) {
lines, err := ReadLines(filename, (page-1)*postsPerPage, page*(postsPerPage+1)-1) lines, err := ReadLines(filename, (page-1)*postsPerPage, page*(postsPerPage+1)-1)
if err != nil { if err != nil {
log.Info("Can't read outbox file") log.Info("Can't read outbox file")
log.Info(err) log.Error(err)
return return
} }
responseMap := make(map[string]interface{}) responseMap := make(map[string]interface{})
@ -171,7 +171,7 @@ func Serve(actors map[string]Actor) {
response, err = json.Marshal(responseMap) response, err = json.Marshal(responseMap)
if err != nil { if err != nil {
log.Info("can't marshal map to json") log.Info("can't marshal map to json")
log.Info(err) log.Error(err)
return return
} }
} }
@ -293,7 +293,7 @@ func Serve(actors map[string]Actor) {
actor, err := LoadActor(username) actor, err := LoadActor(username)
// error out if this actor does not exist // error out if this actor does not exist
if err != nil { if err != nil {
log.Info("Can't create local actor") log.Errorf("Can't create local actor: %s", err)
return return
} }
var page int var page int
@ -314,7 +314,7 @@ func Serve(actors map[string]Actor) {
actor, err := LoadActor(username) actor, err := LoadActor(username)
// error out if this actor does not exist // error out if this actor does not exist
if err != nil { if err != nil {
log.Info("Can't create local actor") log.Errorf("Can't create local actor: %s", err)
return return
} }
post, err := actor.loadItem(hash) post, err := actor.loadItem(hash)
@ -325,7 +325,7 @@ func Serve(actors map[string]Actor) {
} }
postJSON, err := json.Marshal(post) postJSON, err := json.Marshal(post)
if err != nil { if err != nil {
log.Info("failed to marshal json from item " + hash + " text") log.Errorf("failed to marshal json from item %s text", hash)
return return
} }
w.Write(postJSON) w.Write(postJSON)

View File

@ -25,7 +25,7 @@ func NewRemoteActor(iri string) (RemoteActor, error) {
info, err := get(iri) info, err := get(iri)
if err != nil { if err != nil {
log.Info("Couldn't get remote actor information") log.Info("Couldn't get remote actor information")
log.Info(err) log.Error(err)
return RemoteActor{}, err return RemoteActor{}, err
} }
@ -55,7 +55,6 @@ func (ra RemoteActor) getLatestPosts(number int) (map[string]interface{}, error)
} }
func get(iri string) (info map[string]interface{}, err error) { func get(iri string) (info map[string]interface{}, err error) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
req, err := http.NewRequest("GET", iri, buf) req, err := http.NewRequest("GET", iri, buf)
@ -68,10 +67,9 @@ func get(iri string) (info map[string]interface{}, err error) {
req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Accept-Charset", "utf-8")
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
log.Info("Cannot perform the request") log.Info("Cannot perform the request")
log.Info(err) log.Error(err)
return return
} }
@ -79,7 +77,7 @@ func get(iri string) (info map[string]interface{}, err error) {
if !isSuccess(resp.StatusCode) { if !isSuccess(resp.StatusCode) {
err = fmt.Errorf("GET request to %s failed (%d): %s\nResponse: %s \nHeaders: %s", iri, resp.StatusCode, resp.Status, FormatJSON(responseData), FormatHeaders(req.Header)) err = fmt.Errorf("GET request to %s failed (%d): %s\nResponse: %s \nHeaders: %s", iri, resp.StatusCode, resp.Status, FormatJSON(responseData), FormatHeaders(req.Header))
log.Info(err) log.Error(err)
return return
} }
@ -88,7 +86,7 @@ func get(iri string) (info map[string]interface{}, err error) {
if err != nil { if err != nil {
log.Info("something went wrong when unmarshalling the json") log.Info("something went wrong when unmarshalling the json")
log.Info(err) log.Error(err)
return return
} }
info = e.(map[string]interface{}) info = e.(map[string]interface{})