diff --git a/server/http_api.go b/server/http_api.go index 4596c2b..2e5d575 100644 --- a/server/http_api.go +++ b/server/http_api.go @@ -2,7 +2,9 @@ package server import ( "encoding/json" + "errors" "io" + "io/fs" "net/http" "os" "path" @@ -25,6 +27,12 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) { func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) { files, err := os.ReadDir("deploys") + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + err = os.MkdirAll("deploys", os.ModePerm) + } + } + if err != nil { logger.Error(err) w.WriteHeader(http.StatusInternalServerError) @@ -147,7 +155,7 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) { files, err := os.ReadDir(relPath) if err != nil { logger.Error(err) - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusBadRequest) return } @@ -336,7 +344,7 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request) root := path.Join("downloads", name, version) logfiles, err := os.ReadDir(root) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusBadRequest) return }