Просмотр исходного кода

case for 422 when enabling a PR for preview env

Mohammed Nafees 4 лет назад
Родитель
Сommit
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 {