From eb60530cec163c2174c7a3111d2741b342695cd7 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sun, 30 Nov 2025 00:32:23 +0000 Subject: [PATCH] chore: import handler transient error messages --- .../internal/api/handlers/import_handler.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/backend/internal/api/handlers/import_handler.go b/backend/internal/api/handlers/import_handler.go index bbcf4b97..bb58abb0 100644 --- a/backend/internal/api/handlers/import_handler.go +++ b/backend/internal/api/handlers/import_handler.go @@ -278,6 +278,17 @@ func (h *ImportHandler) Upload(c *gin.Context) { return } + // If no hosts were parsed, provide a clearer error when import directives exist + if len(result.Hosts) == 0 { + imports := detectImportDirectives(req.Content) + if len(imports) > 0 { + c.JSON(http.StatusBadRequest, gin.H{"error": "no sites found in uploaded Caddyfile; imports detected; please upload the referenced site files using the multi-file import flow" , "imports": imports}) + return + } + c.JSON(http.StatusBadRequest, gin.H{"error": "no sites found in uploaded Caddyfile"}) + return + } + // Check for conflicts with existing hosts and build conflict details existingHosts, _ := h.proxyHostSvc.List() existingDomainsMap := make(map[string]models.ProxyHost) @@ -415,6 +426,19 @@ func (h *ImportHandler) UploadMulti(c *gin.Context) { return } + // If parsing succeeded but no hosts were found, and imports were present in the main file, + // inform the caller to upload the site files. + if len(result.Hosts) == 0 { + mainContentBytes, _ := os.ReadFile(mainCaddyfile) + imports := detectImportDirectives(string(mainContentBytes)) + if len(imports) > 0 { + c.JSON(http.StatusBadRequest, gin.H{"error": "no sites parsed from main Caddyfile; import directives detected; please include site files in upload", "imports": imports}) + return + } + c.JSON(http.StatusBadRequest, gin.H{"error": "no sites parsed from main Caddyfile"}) + return + } + // Check for conflicts existingHosts, _ := h.proxyHostSvc.List() existingDomains := make(map[string]bool)