Skip to content

Commit 5c42039

Browse files
committed
better error handling
1 parent 7cedf78 commit 5c42039

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

go/apps/request-logger-http/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ func demoHandler(w http.ResponseWriter, r *http.Request) {
6161
result := map[string]string{
6262
"todosApi": statusString(checkTodosAPI(ctx)),
6363
"cache": statusString(checkRedis(ctx)),
64-
"auditLog": statusString(writeAuditLog(ctx, "request-logger demo")),
6564
}
6665

6766
status := http.StatusOK
68-
if result["todosApi"] != "ok" || result["cache"] != "ok" || result["auditLog"] != "ok" {
69-
status = http.StatusBadGateway
67+
if result["todosApi"] != "ok" || result["cache"] != "ok" {
68+
status = http.StatusInternalServerError
7069
}
7170

7271
w.Header().Set("Content-Type", "application/json")
7372
w.WriteHeader(status)
73+
if status == http.StatusInternalServerError {
74+
w.Write([]byte(fmt.Sprintf("One or more dependencies are not healthy: todosApi=%s, cache=%s", result["todosApi"], result["cache"])))
75+
}
7476
if err := json.NewEncoder(w).Encode(result); err != nil {
7577
log.Printf("encode response: %v", err)
7678
}

0 commit comments

Comments
 (0)