Skip to content

Commit 6990789

Browse files
committed
fix: expose safe init failure reason in api handler
1 parent 8e23736 commit 6990789

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

api/index.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ func Handler(w http.ResponseWriter, r *http.Request) {
5454
})
5555

5656
if initErr != nil {
57+
reason := "internal"
58+
errText := strings.ToLower(initErr.Error())
59+
if strings.Contains(errText, "load config") {
60+
reason = "config"
61+
} else if strings.Contains(errText, "connect database") || strings.Contains(errText, "postgres") {
62+
reason = "database"
63+
}
64+
5765
w.Header().Set("Content-Type", "application/json")
5866
w.WriteHeader(http.StatusInternalServerError)
59-
_ = json.NewEncoder(w).Encode(map[string]string{
60-
"error": "backend initialization failed",
67+
_ = json.NewEncoder(w).Encode(map[string]any{
68+
"error": "backend initialization failed",
69+
"reason": reason,
6170
})
6271
return
6372
}

0 commit comments

Comments
 (0)