1a8dfefa77
- Classify Docker errors into categories (socket_not_found, connection_refused, permission_denied, timeout, tls_error) with platform-specific hints - Enrich GET /api/health with structured diagnostics (category, hints, platform) - Expandable hints panel in sidebar when Docker is disconnected - "Retry now" button for immediate re-check - Collapsible raw error details for advanced users
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/alexei/docker-watcher/internal/docker"
|
|
)
|
|
|
|
// getHealth handles GET /api/health.
|
|
// Returns connectivity status for Docker with diagnostic hints on failure.
|
|
func (s *Server) getHealth(w http.ResponseWriter, r *http.Request) {
|
|
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
now := time.Now().UTC().Format(time.RFC3339)
|
|
|
|
if s.docker == nil {
|
|
diag := docker.Diagnose(nil, "")
|
|
respondJSON(w, http.StatusOK, map[string]any{
|
|
"docker": map[string]any{
|
|
"connected": false,
|
|
"error": "docker client not initialized",
|
|
"category": diag.Category,
|
|
"hints": diag.Hints,
|
|
"platform": diag.Platform,
|
|
"checked_at": now,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
|
|
err := s.docker.Ping(ctx)
|
|
if err == nil {
|
|
respondJSON(w, http.StatusOK, map[string]any{
|
|
"docker": map[string]any{
|
|
"connected": true,
|
|
"checked_at": now,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
|
|
diag := docker.Diagnose(err, "")
|
|
respondJSON(w, http.StatusOK, map[string]any{
|
|
"docker": map[string]any{
|
|
"connected": false,
|
|
"error": err.Error(),
|
|
"category": diag.Category,
|
|
"hints": diag.Hints,
|
|
"platform": diag.Platform,
|
|
"checked_at": now,
|
|
},
|
|
})
|
|
}
|