feat: Docker diagnostic hints on disconnection

- 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
This commit is contained in:
2026-03-30 14:05:00 +03:00
parent 4041252028
commit 1a8dfefa77
7 changed files with 284 additions and 21 deletions
+38 -7
View File
@@ -4,22 +4,53 @@ import (
"context"
"net/http"
"time"
"github.com/alexei/docker-watcher/internal/docker"
)
// getHealth handles GET /api/health.
// Returns connectivity status for Docker and other services.
// 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()
dockerOK := false
if s.docker != nil {
if err := s.docker.Ping(ctx); err == nil {
dockerOK = true
}
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": dockerOK,
"docker": map[string]any{
"connected": false,
"error": err.Error(),
"category": diag.Category,
"hints": diag.Hints,
"platform": diag.Platform,
"checked_at": now,
},
})
}