Sfoglia il codice sorgente

Merge pull request #1895 from porter-dev/nafees/hotfixes

[POR-411] [hotfix] Case for status code 422 when enabling a PR for preview env deployment
abelanger5 4 anni fa
parent
commit
fc87c30c01
1 ha cambiato i file con 18 aggiunte e 7 eliminazioni
  1. 18 7
      api/server/handlers/environment/enable_pull_request.go

+ 18 - 7
api/server/handlers/environment/enable_pull_request.go

@@ -1,7 +1,6 @@
 package environment
 
 import (
-	"bytes"
 	"fmt"
 	"net/http"
 	"strconv"
@@ -77,12 +76,24 @@ func (c *EnablePullRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		},
 	)
 
-	buf := new(bytes.Buffer)
-	buf.ReadFrom(ghResp.Body)
-
-	if ghResp != nil && ghResp.StatusCode == 404 {
-		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(fmt.Errorf("workflow file not found"), 404))
-		return
+	if ghResp != nil {
+		if ghResp.StatusCode == 404 {
+			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
+				fmt.Errorf(
+					"Please make sure the preview environment workflow files are present in PR branch %s and are up to"+
+						" date with the default branch", request.BranchFrom,
+				), 404),
+			)
+			return
+		} else if ghResp.StatusCode == 422 {
+			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
+				fmt.Errorf(
+					"Please make sure the workflow files in PR branch %s are up to date with the default branch",
+					request.BranchFrom,
+				), 422),
+			)
+			return
+		}
 	}
 
 	if err != nil {