Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Better error logging for Delete action on /space endpoint (#2280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarifibrahim authored Sep 17, 2018
1 parent f276f3a commit 59561d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
14 changes: 11 additions & 3 deletions controller/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *SpaceController) Delete(ctx *app.DeleteSpaceContext) error {
"error": err,
}, "could not delete codebases")
return jsonapi.JSONErrorResponse(
ctx, errors.NewInternalError(ctx, spaceDeletionErrorExternal))
ctx, errors.NewInternalError(ctx, errs.Wrapf(err, "failed to delete codebases associated with space %s", spaceID)))
}

// now delete the OpenShift resources associated with this space on an
Expand Down Expand Up @@ -278,14 +278,22 @@ func deleteCodebases(
path := client.ListSpaceCodebasesPath(spaceID)
resp, err := cl.ListSpaceCodebases(ctx, path, nil, nil)
if err != nil {
return errors.NewInternalError(ctx,
fmt.Errorf("could not list codebases: %v", err))
log.Error(ctx, map[string]interface{}{
"space_id": spaceID,
"path": path,
"error": err,
}, "failed to list codebases")
return errs.Wrapf(err, "could not list codebases for space: %s", spaceID)
}
defer resp.Body.Close()

if 200 < resp.StatusCode && resp.StatusCode >= 300 {
formattedErrors, err := cl.DecodeJSONAPIErrors(resp)
if err != nil {
log.Error(ctx, map[string]interface{}{
"error": err,
"response": resp,
}, "failed to decode JSON formatted errors returned while listing codebases")
return errors.NewInternalError(ctx,
fmt.Errorf("could not decode JSON formatted errors returned while listing codebases: %v", err))
}
Expand Down
28 changes: 28 additions & 0 deletions controller/space_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,34 @@ func (s *SpaceControllerTestSuite) TestDeleteSpace() {
)
test.DeleteSpaceForbidden(t, svc.Context, svc, ctrl, spaceID, nil)
})

s.T().Run("fail - invalid Space ID", func(t *testing.T) {
var err error
fxt := tf.NewTestFixture(t, s.DB,
tf.Spaces(1, func(fxt *tf.TestFixture, idx int) error {
fxt.Spaces[idx].ID, err = uuid.FromString("788cab16-ba0b-4d48-8587-f187ebc0d9ff")
require.NoError(t, err)
return nil
}),
tf.Codebases(1),
)
spaceID := fxt.Spaces[0].ID
rDeployments, err := recorder.New("../test/data/deployments/deployments_delete_space.ok.yaml")
require.NoError(t, err)
defer rDeployments.Stop()

rCodebase, err := recorder.New("../test/data/codebases/codebases_delete_space.500.yaml")
require.NoError(t, err)
defer rCodebase.Stop()

svc, ctrl := s.SecuredController(
*fxt.Identities[0],
withDeploymentsClient(&http.Client{Transport: rDeployments.Transport}),
withCodebaseClient(&http.Client{Transport: rCodebase.Transport}),
)
_, e := test.DeleteSpaceInternalServerError(t, svc.Context, svc, ctrl, spaceID, nil)
assert.Contains(t, e.String(), "failed to delete codebases associated with space")
})
}

func checkDeleteURL(httpReq *http.Request, expectedDeleteURLs map[string]struct{}, t *testing.T) bool {
Expand Down

0 comments on commit 59561d0

Please sign in to comment.