Skip to content

Commit

Permalink
[Bugfix] Idempotency when trying to create a service twice
Browse files Browse the repository at this point in the history
It was implemented everything for this feature but the error handler when
CAPI V3 answered with a 422 status code with the message
the service instance name is taken.
  • Loading branch information
Hector J Calderon authored and a-b committed Mar 10, 2022
1 parent bef87cf commit 2b4e144
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/cloudcontroller/ccv3/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func handleUnprocessableEntity(errorResponse ccerror.V3Error) error {
case strings.Contains(errorString,
"Assign a droplet before starting this app."):
return ccerror.InvalidStartError{}
case strings.Contains(errorString,
"The service instance name is taken"):
return ccerror.ServiceInstanceNameTakenError{Message: err.Message}
case orgNameTakenRegexp.MatchString(errorString):
return ccerror.OrganizationNameTakenError{UnprocessableEntityError: err}
case roleExistsRegexp.MatchString(errorString):
Expand Down
21 changes: 21 additions & 0 deletions api/cloudcontroller/ccv3/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,27 @@ var _ = Describe("Error Wrapper", func() {
})
})

When("the service instance name is taken", func() {
BeforeEach(func() {
serverResponse = `
{
"errors": [
{
"code": 10008,
"detail": "The service instance name is taken",
"title": "CF-UnprocessableEntity"
}
]
}`
})

It("returns an ServiceInstanceNameTakenError", func() {
Expect(makeError).To(MatchError(ccerror.ServiceInstanceNameTakenError{
Message: "The service instance name is taken",
}))
})
})

When("the buildpack is invalid", func() {
BeforeEach(func() {
serverResponse = `
Expand Down

0 comments on commit 2b4e144

Please sign in to comment.