Feroze Mohideen пре 2 година
родитељ
комит
4f6f01c753
2 измењених фајлова са 13 додато и 0 уклоњено
  1. 9 0
      api/client/api.go
  2. 4 0
      api/client/porter_app.go

+ 9 - 0
api/client/api.go

@@ -153,15 +153,20 @@ func (c *Client) getRequest(relPath string, data interface{}, response interface
 }
 
 type postRequestOpts struct {
+	// retryCount is the number of times to retry the request
 	retryCount uint
+	// onlyRetry500 will only retry the request if the status code is in the 500-range
+	onlyRetry500 bool
 }
 
 func (c *Client) postRequest(relPath string, data interface{}, response interface{}, opts ...postRequestOpts) error {
 	var retryCount uint = 1
+	var onlyRetry500 bool = false
 
 	if len(opts) > 0 {
 		for _, opt := range opts {
 			retryCount = opt.retryCount
+			onlyRetry500 = opt.onlyRetry500
 		}
 	}
 
@@ -191,6 +196,10 @@ func (c *Client) postRequest(relPath string, data interface{}, response interfac
 
 		if i != int(retryCount)-1 {
 			if httpErr != nil {
+				if onlyRetry500 && httpErr.Code < 500 {
+					// if we only retry 500-range responses and this is not a 500-range response, do not retry, instead return the error
+					return fmt.Errorf("%v", httpErr.Error)
+				}
 				fmt.Fprintf(os.Stderr, "Error: %s (status code %d), retrying request...\n", httpErr.Error, httpErr.Code)
 			} else {
 				fmt.Fprintf(os.Stderr, "Error: %v, retrying request...\n", err)

+ 4 - 0
api/client/porter_app.go

@@ -253,6 +253,10 @@ func (c *Client) ApplyPorterApp(
 		),
 		req,
 		resp,
+		postRequestOpts{
+			retryCount:   3,
+			onlyRetry500: true,
+		},
 	)
 
 	return resp, err