From e7781b8f652b9a1a79e043b079090b10b24417ff Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 30 Aug 2024 17:38:06 -0400 Subject: [PATCH] Use log.Error instead of log.Info where necessary Closes #5 --- http.go | 12 ++++++------ remoteActor.go | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/http.go b/http.go index 937ea22..d1338d5 100644 --- a/http.go +++ b/http.go @@ -104,7 +104,7 @@ func Serve(actors map[string]Actor) { totalLines, err := lineCounter(filename) if err != nil { log.Info("Can't read outbox.txt") - log.Info(err) + log.Error(err) return } if pageStr == "" { @@ -126,7 +126,7 @@ func Serve(actors map[string]Actor) { lines, err := ReadLines(filename, (page-1)*postsPerPage, page*(postsPerPage+1)-1) if err != nil { log.Info("Can't read outbox file") - log.Info(err) + log.Error(err) return } responseMap := make(map[string]interface{}) @@ -171,7 +171,7 @@ func Serve(actors map[string]Actor) { response, err = json.Marshal(responseMap) if err != nil { log.Info("can't marshal map to json") - log.Info(err) + log.Error(err) return } } @@ -293,7 +293,7 @@ func Serve(actors map[string]Actor) { actor, err := LoadActor(username) // error out if this actor does not exist if err != nil { - log.Info("Can't create local actor") + log.Errorf("Can't create local actor: %s", err) return } var page int @@ -314,7 +314,7 @@ func Serve(actors map[string]Actor) { actor, err := LoadActor(username) // error out if this actor does not exist if err != nil { - log.Info("Can't create local actor") + log.Errorf("Can't create local actor: %s", err) return } post, err := actor.loadItem(hash) @@ -325,7 +325,7 @@ func Serve(actors map[string]Actor) { } postJSON, err := json.Marshal(post) 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 } w.Write(postJSON) diff --git a/remoteActor.go b/remoteActor.go index e37c56c..f644098 100644 --- a/remoteActor.go +++ b/remoteActor.go @@ -25,7 +25,7 @@ func NewRemoteActor(iri string) (RemoteActor, error) { info, err := get(iri) if err != nil { log.Info("Couldn't get remote actor information") - log.Info(err) + log.Error(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) { - buf := new(bytes.Buffer) 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") resp, err := client.Do(req) - if err != nil { log.Info("Cannot perform the request") - log.Info(err) + log.Error(err) return } @@ -79,7 +77,7 @@ func get(iri string) (info map[string]interface{}, err error) { 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)) - log.Info(err) + log.Error(err) return } @@ -88,7 +86,7 @@ func get(iri string) (info map[string]interface{}, err error) { if err != nil { log.Info("something went wrong when unmarshalling the json") - log.Info(err) + log.Error(err) return } info = e.(map[string]interface{})