Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8(services): handle "operation in progress" error #2139

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions api/cloudcontroller/ccv3/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down