Преглед на файлове

case for 422 when enabling a PR for preview env

Mohammed Nafees преди 4 години
родител
ревизия
0178e164d7
променени са 1 файла, в които са добавени 9 реда и са изтрити 7 реда
  1. 9 7
      api/server/handlers/environment/enable_pull_request.go

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

@@ -1,7 +1,6 @@
 package environment
 
 import (
-	"bytes"
 	"fmt"
 	"net/http"
 	"strconv"
@@ -77,12 +76,15 @@ 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("workflow file not found"), 404))
+			return
+		} else if ghResp.StatusCode == 422 {
+			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
+				fmt.Errorf("please make sure the workflow file in branch %s is up to date", request.BranchFrom), 422))
+			return
+		}
 	}
 
 	if err != nil {