Skip to content

Commit

Permalink
Merge pull request #465 from cloudfoundry/94892746-service-brokers-403
Browse files Browse the repository at this point in the history
Expose api errors for service broker commands
  • Loading branch information
jberkhahn committed Jun 11, 2015
2 parents 119d6d1 + f6746ce commit e2c63ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cf/api/service_brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (repo CloudControllerServiceBrokerRepository) FindByName(name string) (serv
return false
})

if !foundBroker {
if !foundBroker && (apiErr == nil) {
apiErr = errors.NewModelNotFoundError("Service Broker", name)
}

Expand Down
21 changes: 21 additions & 0 deletions cf/api/service_brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ var _ = Describe("Service Brokers Repo", func() {
Expect(apiErr).To(HaveOccurred())
Expect(apiErr.Error()).To(Equal("Service Broker my-broker not found"))
})

It("returns an error when listing service brokers returns an api error", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/service_brokers?q=name%3Amy-broker",
Response: testnet.TestResponse{Status: http.StatusForbidden, Body: `{
"code": 10003,
"description": "You are not authorized to perform the requested action",
"error_code": "CF-NotAuthorized"
}`},
})

ts, handler, repo := createServiceBrokerRepo(req)
defer ts.Close()

_, apiErr := repo.FindByName("my-broker")

Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).To(HaveOccurred())
Expect(apiErr.Error()).To(Equal("Server error, status code: 403, error code: 10003, message: You are not authorized to perform the requested action"))
})
})

Describe("FindByGuid", func() {
Expand Down

0 comments on commit e2c63ef

Please sign in to comment.