Skip to content

Commit

Permalink
Further improved log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterEvarior committed May 24, 2022
1 parent 9c65fda commit 084c9c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cocopasty-backend/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func CreateDatabaseClient() (*database, error) {
}

func (d *database) CreateEntry(ctx context.Context, code string) error {
log.Debug("Setting value in Redis...")
log.Debug("Setting value in Redis")
status := d.connection.Set(ctx, keyName, code, 0)

return status.Err()
}

func (d *database) ReadEntry(ctx context.Context) (string, error) {
log.Debug("Getting value from Redis...")
log.Debug("Getting value from Redis")

return d.connection.Get(ctx, keyName).Result()
}
Expand All @@ -54,6 +54,8 @@ func getPassword() string {
input := os.Getenv("REDIS_PASSWORD")
if input == "" {
log.Info("No Redis password was set")
} else {
log.Info("A Redis password was set")
}

return input
Expand Down
9 changes: 3 additions & 6 deletions cocopasty-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ func handlePosts(w http.ResponseWriter, r *http.Request) {

err := json.NewDecoder(r.Body).Decode(&newSnippet)
if err != nil {
log.Error("Could not decode JSON")
log.Error(err)
log.Errorf("Could not decode JSON: ", err)
w.WriteHeader(http.StatusBadRequest)
return
}

err = databaseClient.CreateEntry(ctx, newSnippet.Code)
if err != nil {
log.Error("Failed to save snippet in Redis")
log.Error(err)
log.Errorf("Failed to save snippet in Redis: ", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand All @@ -86,8 +84,7 @@ func handleGets(w http.ResponseWriter, r *http.Request) {
value, err := databaseClient.ReadEntry(ctx)

if err != nil {
log.Error("Could not retrieve snippet from Redis")
log.Error(err)
log.Error("Could not retrieve snippet from Redis: ", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down

0 comments on commit 084c9c6

Please sign in to comment.