diff --git a/client.go b/client.go index ed31da2..d90c010 100644 --- a/client.go +++ b/client.go @@ -89,7 +89,7 @@ func (client Client) dispatchRequest(request *http.Request) ([]byte, error) { // as instructed and retry the request. if err != nil { serverError, ok := errors.Cause(err).(ServerError) - if ok && serverError.StatusCode == http.StatusServiceUnavailable { + if ok && (serverError.StatusCode == http.StatusServiceUnavailable || serverError.StatusCode == http.StatusConflict) { retryTimeInt, errConv := strconv.Atoi(serverError.Header.Get(RetryAfterHeaderName)) if errConv == nil { select { diff --git a/client_test.go b/client_test.go index 54d9320..a0db8b3 100644 --- a/client_test.go +++ b/client_test.go @@ -78,6 +78,22 @@ func (suite *ClientSuite) TestClientDispatchRequestRetries503(c *gc.C) { c.Check(*server.requests, jc.DeepEquals, expectedRequestsContent) } +func (suite *ClientSuite) TestClientDispatchRequestRetries409(c *gc.C) { + URI := "/some/url/?param1=test" + server := newFlakyServer(URI, 409, NumberOfRetries) + defer server.Close() + client, err := NewAnonymousClient(server.URL, "1.0") + c.Assert(err, jc.ErrorIsNil) + content := "content" + request, err := http.NewRequest("GET", server.URL+URI, io.NopCloser(strings.NewReader(content))) + c.Assert(err, jc.ErrorIsNil) + + _, err = client.dispatchRequest(request) + + c.Assert(err, jc.ErrorIsNil) + c.Check(*server.nbRequests, gc.Equals, NumberOfRetries+1) +} + func (suite *ClientSuite) TestTLSClientDispatchRequestRetries503NilBody(c *gc.C) { URI := "/some/path" server := newFlakyTLSServer(URI, 503, NumberOfRetries) diff --git a/testing.go b/testing.go index 494216d..8d45759 100644 --- a/testing.go +++ b/testing.go @@ -69,7 +69,7 @@ func newFlakyServer(uri string, code int, nbFlakyResponses int) *flakyServer { errorMsg := fmt.Sprintf("Error 404: page not found (expected '%v', got '%v').", uri, request.URL.String()) http.Error(writer, errorMsg, http.StatusNotFound) } else if nbRequests <= nbFlakyResponses { - if code == http.StatusServiceUnavailable { + if code == http.StatusServiceUnavailable || code == http.StatusConflict { writer.Header().Set("Retry-After", "0") } writer.WriteHeader(code)