Skip to content

Commit

Permalink
Merge pull request concourse#9011 from Pix4D/go-concourse-connection-…
Browse files Browse the repository at this point in the history
…client-improve-error-msg

go-concourse:connection client prints response body to the end user
  • Loading branch information
xtremerui authored Nov 28, 2024
2 parents b45e1d7 + fa06840 commit 67b05c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion go-concourse/concourse/internal/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ func (connection *connection) populateResponse(response *http.Response, returnRe
}

if response.StatusCode == http.StatusForbidden {
return ErrForbidden
body, _ := io.ReadAll(response.Body)
return ForbiddenError{Reason: string(body)}
}

if response.StatusCode < 200 || response.StatusCode >= 300 {
Expand Down
25 changes: 25 additions & 0 deletions go-concourse/concourse/internal/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,31 @@ var _ = Describe("ATC Connection", func() {
})
})

Describe("403 response", func() {
BeforeEach(func() {
atcServer = ghttp.NewServer()
connection = NewConnection(atcServer.URL(), nil, tracing)
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/api/v1/teams/main/pipelines/foo"),
ghttp.RespondWith(http.StatusForbidden, "problem"),
),
)
})
It("returns back ForbiddenError", func() {
err := connection.Send(Request{
RequestName: atc.DeletePipeline,
Params: rata.Params{
"pipeline_name": "foo",
"team_name": atc.DefaultTeamName,
},
}, nil)
fe, ok := err.(ForbiddenError)
Expect(ok).To(BeTrue())
Expect(fe.Reason).To(Equal("problem"))
})
})

Describe("404 response", func() {
Context("when the response does not contain JSONAPI errors", func() {
BeforeEach(func() {
Expand Down

0 comments on commit 67b05c3

Please sign in to comment.