Skip to content

Commit

Permalink
v8(services): handle "operation in progress" error (#2139)
Browse files Browse the repository at this point in the history
- reports the message from the cloud controller
- no longer reports as an unexpected error

[#176379736](https://www.pivotaltracker.com/story/show/176379736)
blgm authored Feb 16, 2021
1 parent a7375c2 commit 93a421a
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ccerror

// ServiceInstanceOperationInProgressError is returned when an operation
// cannot proceed because an operation is already in progress
type ServiceInstanceOperationInProgressError struct {
Message string
}

func (e ServiceInstanceOperationInProgressError) Error() string {
return e.Message
}
19 changes: 13 additions & 6 deletions api/cloudcontroller/ccv3/errors.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,10 @@ import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
)

const taskWorkersUnavailable = "CF-TaskWorkersUnavailable"
const (
taskWorkersUnavailable = "CF-TaskWorkersUnavailable"
operationInProgress = "CF-AsyncServiceInstanceOperationInProgress"
)

// errorWrapper is the wrapper that converts responses with 4xx and 5xx status
// codes to an error.
@@ -71,13 +74,17 @@ func convert400(rawHTTPStatusErr ccerror.RawHTTPStatusError, request *cloudcontr
return ccerror.TaskWorkersUnavailableError{Message: firstErr.Detail}
}
return ccerror.ServiceUnavailableError{Message: firstErr.Detail}
default:
return ccerror.V3UnexpectedResponseError{
ResponseCode: rawHTTPStatusErr.StatusCode,
RequestIDs: rawHTTPStatusErr.RequestIDs,
V3ErrorResponse: errorResponse,
case http.StatusConflict:
if firstErr.Title == operationInProgress {
return ccerror.ServiceInstanceOperationInProgressError{Message: firstErr.Detail}
}
}

return ccerror.V3UnexpectedResponseError{
ResponseCode: rawHTTPStatusErr.StatusCode,
RequestIDs: rawHTTPStatusErr.RequestIDs,
V3ErrorResponse: errorResponse,
}
}

func convert500(rawHTTPStatusErr ccerror.RawHTTPStatusError) error {
27 changes: 27 additions & 0 deletions api/cloudcontroller/ccv3/errors_test.go
Original file line number Diff line number Diff line change
@@ -275,6 +275,33 @@ var _ = Describe("Error Wrapper", func() {
})
})

Context("(409) Conflict", func() {
BeforeEach(func() {
serverResponseCode = http.StatusConflict
})

When("a service instance operation is in progress", func() {
BeforeEach(func() {
serverResponse = `
{
"errors": [
{
"code": 60016,
"detail": "An operation for service instance foo is in progress.",
"title": "CF-AsyncServiceInstanceOperationInProgress"
}
]
}`
})

It("returns a ServiceInstanceOperationInProgressError", func() {
Expect(makeError).To(MatchError(ccerror.ServiceInstanceOperationInProgressError{
Message: "An operation for service instance foo is in progress.",
}))
})
})
})

Context("(422) Unprocessable Entity", func() {
BeforeEach(func() {
serverResponseCode = http.StatusUnprocessableEntity

0 comments on commit 93a421a

Please sign in to comment.