From 0b07ca4c5e67cc834fc1a525be47afa4bb527aad Mon Sep 17 00:00:00 2001 From: Fimeg Date: Wed, 29 Oct 2025 15:31:46 -0400 Subject: [PATCH] fix: improve setup error handling and health endpoint - Add /api/v1/health endpoint for web app compatibility - Add detailed error logging to setup handler - Show actual error messages when config save fails - Helps debug permission and filesystem issues --- aggregator-server/cmd/server/main.go | 5 ++++- aggregator-server/internal/api/handlers/setup.go | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/aggregator-server/cmd/server/main.go b/aggregator-server/cmd/server/main.go index b127653..10f2fae 100644 --- a/aggregator-server/cmd/server/main.go +++ b/aggregator-server/cmd/server/main.go @@ -23,10 +23,13 @@ func startWelcomeModeServer() { // Add CORS middleware router.Use(middleware.CORSMiddleware()) - // Health check + // Health check (both endpoints for compatibility) router.GET("/health", func(c *gin.Context) { c.JSON(200, gin.H{"status": "waiting for configuration"}) }) + router.GET("/api/v1/health", func(c *gin.Context) { + c.JSON(200, gin.H{"status": "waiting for configuration"}) + }) // Welcome page with setup instructions router.GET("/", setupHandler.ShowSetupPage) diff --git a/aggregator-server/internal/api/handlers/setup.go b/aggregator-server/internal/api/handlers/setup.go index 9a7174e..23c01c7 100644 --- a/aggregator-server/internal/api/handlers/setup.go +++ b/aggregator-server/internal/api/handlers/setup.go @@ -291,13 +291,15 @@ LATEST_AGENT_VERSION=0.1.16`, // Write configuration to persistent location configDir := "/app/config" if err := os.MkdirAll(configDir, 0755); err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create config directory"}) + fmt.Printf("Failed to create config directory: %v\n", err) + c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to create config directory: %v", err)}) return } envPath := filepath.Join(configDir, ".env") if err := os.WriteFile(envPath, []byte(envContent), 0600); err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save configuration"}) + fmt.Printf("Failed to save configuration: %v\n", err) + c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to save configuration: %v", err)}) return }